finalised things that could be final

This commit is contained in:
Alexandros Schillings
2015-07-03 14:32:19 +01:00
parent 67bc13a9c2
commit 56e27ffab1
25 changed files with 134 additions and 112 deletions
+15
View File
@@ -0,0 +1,15 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<option name="myLocal" value="true" />
<inspection_tool class="GroovyVariableCanBeFinal" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="LoggerInitializedWithForeignClass" enabled="false" level="WARNING" enabled_by_default="false">
<option name="loggerClassName" value="org.apache.log4j.Logger,org.slf4j.LoggerFactory,org.apache.commons.logging.LogFactory,java.util.logging.Logger" />
<option name="loggerFactoryMethodName" value="getLogger,getLogger,getLog,getLogger" />
</inspection_tool>
<inspection_tool class="MissingOverrideAnnotation" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoreObjectMethods" value="true" />
<option name="ignoreAnonymousClassMethods" value="false" />
</inspection_tool>
</profile>
</component>
+7
View File
@@ -0,0 +1,7 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="PROJECT_PROFILE" value="Project Default" />
<option name="USE_PROJECT_PROFILE" value="true" />
<version value="1.0" />
</settings>
</component>
@@ -47,11 +47,11 @@ public class BluetoothLeDevice implements Parcelable{
/** The Constant CREATOR. */ /** The Constant CREATOR. */
public static final Parcelable.Creator<BluetoothLeDevice> CREATOR = new Parcelable.Creator<BluetoothLeDevice>() { public static final Parcelable.Creator<BluetoothLeDevice> CREATOR = new Parcelable.Creator<BluetoothLeDevice>() {
public BluetoothLeDevice createFromParcel(Parcel in) { public BluetoothLeDevice createFromParcel(final Parcel in) {
return new BluetoothLeDevice(in); return new BluetoothLeDevice(in);
} }
public BluetoothLeDevice[] newArray(int size) { public BluetoothLeDevice[] newArray(final int size) {
return new BluetoothLeDevice[size]; return new BluetoothLeDevice[size];
} }
}; };
@@ -64,7 +64,7 @@ public class BluetoothLeDevice implements Parcelable{
* @param scanRecord the scan record of the device * @param scanRecord the scan record of the device
* @param timestamp the timestamp of the RSSI reading * @param timestamp the timestamp of the RSSI reading
*/ */
public BluetoothLeDevice(BluetoothDevice device, int rssi, byte[] scanRecord, long timestamp){ public BluetoothLeDevice(final BluetoothDevice device, final int rssi, final byte[] scanRecord, final long timestamp){
mDevice = device; mDevice = device;
mFirstRssi = rssi; mFirstRssi = rssi;
mFirstTimestamp = timestamp; mFirstTimestamp = timestamp;
@@ -79,7 +79,7 @@ public class BluetoothLeDevice implements Parcelable{
* *
* @param device the device * @param device the device
*/ */
public BluetoothLeDevice(BluetoothLeDevice device) { public BluetoothLeDevice(final BluetoothLeDevice device) {
mCurrentRssi = device.getRssi(); mCurrentRssi = device.getRssi();
mCurrentTimestamp = device.getTimestamp(); mCurrentTimestamp = device.getTimestamp();
mDevice = device.getDevice(); mDevice = device.getDevice();
@@ -97,7 +97,7 @@ public class BluetoothLeDevice implements Parcelable{
* @param in the in * @param in the in
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected BluetoothLeDevice(Parcel in) { protected BluetoothLeDevice(final Parcel in) {
final Bundle b = in.readBundle(getClass().getClassLoader()); final Bundle b = in.readBundle(getClass().getClassLoader());
mCurrentRssi = b.getInt(PARCEL_EXTRA_CURRENT_RSSI, 0); mCurrentRssi = b.getInt(PARCEL_EXTRA_CURRENT_RSSI, 0);
@@ -116,7 +116,7 @@ public class BluetoothLeDevice implements Parcelable{
* @param timestamp the timestamp * @param timestamp the timestamp
* @param rssiReading the rssi reading * @param rssiReading the rssi reading
*/ */
private void addToRssiLog(long timestamp, int rssiReading){ private void addToRssiLog(final long timestamp, final int rssiReading){
synchronized (mRssiLog) { synchronized (mRssiLog) {
if(timestamp - mCurrentTimestamp > LOG_INVALIDATION_THRESHOLD){ if(timestamp - mCurrentTimestamp > LOG_INVALIDATION_THRESHOLD){
mRssiLog.clear(); mRssiLog.clear();
@@ -140,14 +140,14 @@ public class BluetoothLeDevice implements Parcelable{
* @see java.lang.Object#equals(java.lang.Object) * @see java.lang.Object#equals(java.lang.Object)
*/ */
@Override @Override
public boolean equals(Object obj) { public boolean equals(final Object obj) {
if (this == obj) if (this == obj)
return true; return true;
if (obj == null) if (obj == null)
return false; return false;
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
BluetoothLeDevice other = (BluetoothLeDevice) obj; final BluetoothLeDevice other = (BluetoothLeDevice) obj;
if (mCurrentRssi != other.mCurrentRssi) if (mCurrentRssi != other.mCurrentRssi)
return false; return false;
if (mCurrentTimestamp != other.mCurrentTimestamp) if (mCurrentTimestamp != other.mCurrentTimestamp)
@@ -348,7 +348,7 @@ public class BluetoothLeDevice implements Parcelable{
* @param timestamp the timestamp * @param timestamp the timestamp
* @param rssiReading the rssi reading * @param rssiReading the rssi reading
*/ */
public void updateRssiReading(long timestamp, int rssiReading){ public void updateRssiReading(final long timestamp, final int rssiReading){
addToRssiLog(timestamp, rssiReading); addToRssiLog(timestamp, rssiReading);
} }
@@ -356,7 +356,7 @@ public class BluetoothLeDevice implements Parcelable{
* @see android.os.Parcelable#writeToParcel(android.os.Parcel, int) * @see android.os.Parcelable#writeToParcel(android.os.Parcel, int)
*/ */
@Override @Override
public void writeToParcel(Parcel parcel, int arg1) { public void writeToParcel(final Parcel parcel, final int arg1) {
final Bundle b = new Bundle(getClass().getClassLoader()); final Bundle b = new Bundle(getClass().getClassLoader());
b.putByteArray(PARCEL_EXTRA_DEVICE_SCANRECORD, mScanRecord); b.putByteArray(PARCEL_EXTRA_DEVICE_SCANRECORD, mScanRecord);
@@ -380,7 +380,7 @@ public class BluetoothLeDevice implements Parcelable{
* @param bondState the bond state * @param bondState the bond state
* @return the string * @return the string
*/ */
private static String resolveBondingState(int bondState){ private static String resolveBondingState(final int bondState){
switch (bondState){ switch (bondState){
case BluetoothDevice.BOND_BONDED: case BluetoothDevice.BOND_BONDED:
return "Paired"; return "Paired";
@@ -19,7 +19,7 @@ public class IBeaconDevice extends BluetoothLeDevice{
* @param scanRecord the scanRecord * @param scanRecord the scanRecord
* @throws IllegalArgumentException if the passed device is not an iBeacon * @throws IllegalArgumentException if the passed device is not an iBeacon
*/ */
public IBeaconDevice(BluetoothDevice device, int rssi, byte[] scanRecord) { public IBeaconDevice(final BluetoothDevice device, final int rssi, final byte[] scanRecord) {
super(device, rssi, scanRecord, 0); super(device, rssi, scanRecord, 0);
validate(); validate();
mIBeaconData = new IBeaconManufacturerData(this); mIBeaconData = new IBeaconManufacturerData(this);
@@ -34,7 +34,7 @@ public class IBeaconDevice extends BluetoothLeDevice{
* @param timestamp the timestamp of the RSSI measurement * @param timestamp the timestamp of the RSSI measurement
* @throws IllegalArgumentException if the passed device is not an iBeacon * @throws IllegalArgumentException if the passed device is not an iBeacon
*/ */
public IBeaconDevice(BluetoothDevice device, int rssi, byte[] scanRecord, long timestamp){ public IBeaconDevice(final BluetoothDevice device, final int rssi, final byte[] scanRecord, final long timestamp){
super(device, rssi, scanRecord, timestamp); super(device, rssi, scanRecord, timestamp);
validate(); validate();
mIBeaconData = new IBeaconManufacturerData(this); mIBeaconData = new IBeaconManufacturerData(this);
@@ -47,13 +47,13 @@ public class IBeaconDevice extends BluetoothLeDevice{
* @param device the device * @param device the device
* @throws IllegalArgumentException if the passed device is not an iBeacon * @throws IllegalArgumentException if the passed device is not an iBeacon
*/ */
public IBeaconDevice(BluetoothLeDevice device){ public IBeaconDevice(final BluetoothLeDevice device){
super(device); super(device);
validate(); validate();
mIBeaconData = new IBeaconManufacturerData(this); mIBeaconData = new IBeaconManufacturerData(this);
} }
private IBeaconDevice(Parcel in) { private IBeaconDevice(final Parcel in) {
super(in); super(in);
validate(); validate();
mIBeaconData = new IBeaconManufacturerData(this); mIBeaconData = new IBeaconManufacturerData(this);
@@ -136,22 +136,22 @@ public final class AdRecord implements Parcelable{
public static final Parcelable.Creator<AdRecord> CREATOR = new Parcelable.Creator<AdRecord>() { public static final Parcelable.Creator<AdRecord> CREATOR = new Parcelable.Creator<AdRecord>() {
public AdRecord createFromParcel(Parcel in) { public AdRecord createFromParcel(final Parcel in) {
return new AdRecord(in); return new AdRecord(in);
} }
public AdRecord[] newArray(int size) { public AdRecord[] newArray(final int size) {
return new AdRecord[size]; return new AdRecord[size];
} }
}; };
public AdRecord(int length, int type, byte[] data) { public AdRecord(final int length, final int type, final byte[] data) {
mLength = length; mLength = length;
mType = type; mType = type;
mData = data; mData = data;
} }
public AdRecord(Parcel in) { public AdRecord(final Parcel in) {
final Bundle b = in.readBundle(getClass().getClassLoader()); final Bundle b = in.readBundle(getClass().getClassLoader());
mLength = b.getInt(PARCEL_RECORD_LENGTH); mLength = b.getInt(PARCEL_RECORD_LENGTH);
mType = b.getInt(PARCEL_RECORD_TYPE); mType = b.getInt(PARCEL_RECORD_TYPE);
@@ -185,7 +185,7 @@ public final class AdRecord implements Parcelable{
} }
@Override @Override
public void writeToParcel(Parcel parcel, int arg1) { public void writeToParcel(final Parcel parcel, final int arg1) {
final Bundle b = new Bundle(getClass().getClassLoader()); final Bundle b = new Bundle(getClass().getClassLoader());
b.putInt(PARCEL_RECORD_LENGTH, mLength); b.putInt(PARCEL_RECORD_LENGTH, mLength);
@@ -195,7 +195,7 @@ public final class AdRecord implements Parcelable{
parcel.writeBundle(b); parcel.writeBundle(b);
} }
private static String getHumanReadableAdType(int type){ private static String getHumanReadableAdType(final int type){
switch(type){ switch(type){
case TYPE_CONNECTION_INTERVAL_RANGE: case TYPE_CONNECTION_INTERVAL_RANGE:
return "Slave Connection Interval Range"; return "Slave Connection Interval Range";
@@ -19,16 +19,16 @@ public class AdRecordStore implements Parcelable{
private final String mLocalNameShort; private final String mLocalNameShort;
public static final Parcelable.Creator<AdRecordStore> CREATOR = new Parcelable.Creator<AdRecordStore>() { public static final Parcelable.Creator<AdRecordStore> CREATOR = new Parcelable.Creator<AdRecordStore>() {
public AdRecordStore createFromParcel(Parcel in) { public AdRecordStore createFromParcel(final Parcel in) {
return new AdRecordStore(in); return new AdRecordStore(in);
} }
public AdRecordStore[] newArray(int size) { public AdRecordStore[] newArray(final int size) {
return new AdRecordStore[size]; return new AdRecordStore[size];
} }
}; };
public AdRecordStore(Parcel in) { public AdRecordStore(final Parcel in) {
final Bundle b = in.readBundle(getClass().getClassLoader()); final Bundle b = in.readBundle(getClass().getClassLoader());
mAdRecords = b.getSparseParcelableArray("records_array"); mAdRecords = b.getSparseParcelableArray("records_array");
mLocalNameComplete = b.getString("local_name_complete"); mLocalNameComplete = b.getString("local_name_complete");
@@ -83,7 +83,7 @@ public class AdRecordStore implements Parcelable{
* @param record the record * @param record the record
* @return the record * @return the record
*/ */
public AdRecord getRecord(int record){ public AdRecord getRecord(final int record){
return mAdRecords.get(record); return mAdRecords.get(record);
} }
@@ -93,7 +93,7 @@ public class AdRecordStore implements Parcelable{
* @param record the record * @param record the record
* @return the record data as string * @return the record data as string
*/ */
public String getRecordDataAsString(int record){ public String getRecordDataAsString(final int record){
return AdRecordUtils.getRecordDataAsString( return AdRecordUtils.getRecordDataAsString(
mAdRecords.get(record)); mAdRecords.get(record));
} }
@@ -113,7 +113,7 @@ public class AdRecordStore implements Parcelable{
* @param record the record * @param record the record
* @return true, if is record present * @return true, if is record present
*/ */
public boolean isRecordPresent(int record){ public boolean isRecordPresent(final int record){
return mAdRecords.indexOfKey(record) >= 0; return mAdRecords.indexOfKey(record) >= 0;
} }
@@ -129,7 +129,7 @@ public class AdRecordStore implements Parcelable{
* @see android.os.Parcelable#writeToParcel(android.os.Parcel, int) * @see android.os.Parcelable#writeToParcel(android.os.Parcel, int)
*/ */
@Override @Override
public void writeToParcel(Parcel parcel, int arg1) { public void writeToParcel(final Parcel parcel, final int arg1) {
final Bundle b = new Bundle(); final Bundle b = new Bundle();
b.putString("local_name_complete", mLocalNameComplete); b.putString("local_name_complete", mLocalNameComplete);
b.putString("local_name_short", mLocalNameShort); b.putString("local_name_short", mLocalNameShort);
@@ -145,7 +145,7 @@ public class AdRecordStore implements Parcelable{
* @param sparseArray the sparse array * @param sparseArray the sparse array
* @return the collection * @return the collection
*/ */
public static <C> Collection<C> asList(SparseArray<C> sparseArray) { public static <C> Collection<C> asList(final SparseArray<C> sparseArray) {
if (sparseArray == null) return null; if (sparseArray == null) return null;
final Collection<C> arrayList = new ArrayList<C>(sparseArray.size()); final Collection<C> arrayList = new ArrayList<C>(sparseArray.size());
@@ -53,7 +53,7 @@ public final class IBeaconManufacturerData {
private final int mMinor; private final int mMinor;
private final String mUUID; private final String mUUID;
public IBeaconManufacturerData(BluetoothLeDevice device){ public IBeaconManufacturerData(final BluetoothLeDevice device){
this(device.getAdRecordStore().getRecord(AdRecord.TYPE_MANUFACTURER_SPECIFIC_DATA).getData()); this(device.getAdRecordStore().getRecord(AdRecord.TYPE_MANUFACTURER_SPECIFIC_DATA).getData());
} }
@@ -63,7 +63,7 @@ public final class IBeaconManufacturerData {
* @param data the {@link uk.co.alt236.bluetoothlelib.device.adrecord.AdRecord#TYPE_MANUFACTURER_SPECIFIC_DATA} data array * @param data the {@link uk.co.alt236.bluetoothlelib.device.adrecord.AdRecord#TYPE_MANUFACTURER_SPECIFIC_DATA} data array
* @throws IndexOutOfBoundsException if the data array is shorter than expected * @throws IndexOutOfBoundsException if the data array is shorter than expected
*/ */
public IBeaconManufacturerData(byte[] data){ public IBeaconManufacturerData(final byte[] data){
mData = data; mData = data;
mCompanyIdentidier = ByteUtils.getIntFrom2ByteArray( mCompanyIdentidier = ByteUtils.getIntFrom2ByteArray(
@@ -4,7 +4,7 @@ import android.bluetooth.BluetoothClass;
public class BluetoothClassResolver { public class BluetoothClassResolver {
public static String resolveDeviceClass(int btClass){ public static String resolveDeviceClass(final int btClass){
switch (btClass){ switch (btClass){
case BluetoothClass.Device.AUDIO_VIDEO_CAMCORDER: case BluetoothClass.Device.AUDIO_VIDEO_CAMCORDER:
return "A/V, Camcorder"; return "A/V, Camcorder";
@@ -318,7 +318,7 @@ public class CompanyIdentifierResolver {
private static final SparseArray<String> COMPANY_NAME_MAP = populateCompanyNameMap(); private static final SparseArray<String> COMPANY_NAME_MAP = populateCompanyNameMap();
public static String getCompanyName(int companyId, String fallback){ public static String getCompanyName(final int companyId, final String fallback){
final String name = COMPANY_NAME_MAP.get(companyId); final String name = COMPANY_NAME_MAP.get(companyId);
return name == null ? fallback : name; return name == null ? fallback : name;
} }
@@ -195,7 +195,7 @@ public class GattAttributeResolver {
private final static Map<String, String> sGattAttributesMap = populateGattAttributesMap(); private final static Map<String, String> sGattAttributesMap = populateGattAttributesMap();
public static String getAttributeName(String uuid, String fallback){ public static String getAttributeName(final String uuid, final String fallback){
final String name = sGattAttributesMap.get(uuid.toLowerCase(Locale.US)); final String name = sGattAttributesMap.get(uuid.toLowerCase(Locale.US));
return name == null ? fallback : name; return name == null ? fallback : name;
} }
@@ -93,7 +93,7 @@ public class AdRecordUtils {
return Collections.unmodifiableMap(records); return Collections.unmodifiableMap(records);
} }
public static SparseArray<AdRecord> parseScanRecordAsSparseArray(byte[] scanRecord) { public static SparseArray<AdRecord> parseScanRecordAsSparseArray(final byte[] scanRecord) {
final SparseArray<AdRecord> records = new SparseArray<AdRecord>(); final SparseArray<AdRecord> records = new SparseArray<AdRecord>();
int index = 0; int index = 0;
@@ -40,7 +40,7 @@ public class ByteUtils {
* @param prefix the prefix * @param prefix the prefix
* @return true, if successful * @return true, if successful
*/ */
public static boolean doesArrayBeginWith(byte[] array, byte[] prefix){ public static boolean doesArrayBeginWith(final byte[] array, final byte[] prefix){
if(array.length < prefix.length){return false;} if(array.length < prefix.length){return false;}
for(int i = 0; i < prefix.length; i++){ for(int i = 0; i < prefix.length; i++){
@@ -58,7 +58,7 @@ public class ByteUtils {
* @param input the input * @param input the input
* @return the int from the array * @return the int from the array
*/ */
public static int getIntFrom2ByteArray(byte[] input){ public static int getIntFrom2ByteArray(final byte[] input){
final byte[] result = new byte[4]; final byte[] result = new byte[4];
result[0] = 0; result[0] = 0;
@@ -108,7 +108,7 @@ public class ByteUtils {
* @param array the array * @param array the array
* @return the byte[] * @return the byte[]
*/ */
public static byte[] invertArray(byte[] array){ public static byte[] invertArray(final byte[] array){
final int size = array.length; final int size = array.length;
byte temp; byte temp;
@@ -10,7 +10,7 @@ public class IBeaconUtils {
private static final byte[] MANUFACTURER_DATA_IBEACON_PREFIX = new byte[]{0x4C, 0x00, 0x02, 0x15}; private static final byte[] MANUFACTURER_DATA_IBEACON_PREFIX = new byte[]{0x4C, 0x00, 0x02, 0x15};
public static IBeaconDistanceDescriptor getDistanceDescriptor(double accuracy){ public static IBeaconDistanceDescriptor getDistanceDescriptor(final double accuracy){
if(accuracy < DISTANCE_THRESHOLD_WTF){ if(accuracy < DISTANCE_THRESHOLD_WTF){
return IBeaconDistanceDescriptor.UNKNOWN; return IBeaconDistanceDescriptor.UNKNOWN;
} }
@@ -35,12 +35,12 @@ public class IBeaconUtils {
* @param rssi the RSSI value of the iBeacon * @param rssi the RSSI value of the iBeacon
* @return the calculated Accuracy * @return the calculated Accuracy
*/ */
public static double calculateAccuracy(int txPower, double rssi) { public static double calculateAccuracy(final int txPower, final double rssi) {
if (rssi == 0) { if (rssi == 0) {
return -1.0; // if we cannot determine accuracy, return -1. return -1.0; // if we cannot determine accuracy, return -1.
} }
double ratio = rssi*1.0/txPower; final double ratio = rssi*1.0/txPower;
if (ratio < 1.0) { if (ratio < 1.0) {
return Math.pow(ratio,10); return Math.pow(ratio,10);
} }
@@ -56,7 +56,7 @@ public class IBeaconUtils {
* @param device a {@link uk.co.alt236.bluetoothlelib.device.BluetoothLeDevice} device. * @param device a {@link uk.co.alt236.bluetoothlelib.device.BluetoothLeDevice} device.
* @return true if the device is an iBeacon, false otherwise * @return true if the device is an iBeacon, false otherwise
*/ */
public static boolean isThisAnIBeacon(BluetoothLeDevice device){ public static boolean isThisAnIBeacon(final BluetoothLeDevice device){
return isThisAnIBeacon( return isThisAnIBeacon(
device.getAdRecordStore().getRecordDataAsString(AdRecord.TYPE_MANUFACTURER_SPECIFIC_DATA).getBytes()); device.getAdRecordStore().getRecordDataAsString(AdRecord.TYPE_MANUFACTURER_SPECIFIC_DATA).getBytes());
} }
@@ -67,7 +67,7 @@ public class IBeaconUtils {
* @param manufacturerData a Bluetooth LE device's raw manufacturerData. * @param manufacturerData a Bluetooth LE device's raw manufacturerData.
* @return * @return
*/ */
public static boolean isThisAnIBeacon(byte[] manufacturerData){ public static boolean isThisAnIBeacon(final byte[] manufacturerData){
if(manufacturerData == null){return false;} if(manufacturerData == null){return false;}
// An iBeacon record must be at least 25 chars long // An iBeacon record must be at least 25 chars long
@@ -8,13 +8,13 @@ public class LimitedLinkHashMap<K, V> extends LinkedHashMap<K, V>{
private final int mMaxSize; private final int mMaxSize;
public LimitedLinkHashMap(int maxSize){ public LimitedLinkHashMap(final int maxSize){
super(maxSize + 1, 1, false); super(maxSize + 1, 1, false);
mMaxSize = maxSize; mMaxSize = maxSize;
} }
@Override @Override
protected boolean removeEldestEntry(Map.Entry<K, V> eldest) { protected boolean removeEldestEntry(final Map.Entry<K, V> eldest) {
return this.size() > mMaxSize; return this.size() > mMaxSize;
} }
} }
@@ -81,7 +81,7 @@ public class DeviceControlActivity extends Activity {
// Code to manage Service lifecycle. // Code to manage Service lifecycle.
private final ServiceConnection mServiceConnection = new ServiceConnection() { private final ServiceConnection mServiceConnection = new ServiceConnection() {
@Override @Override
public void onServiceConnected(ComponentName componentName, IBinder service) { public void onServiceConnected(final ComponentName componentName, final IBinder service) {
mBluetoothLeService = ((BluetoothLeService.LocalBinder) service).getService(); mBluetoothLeService = ((BluetoothLeService.LocalBinder) service).getService();
if (!mBluetoothLeService.initialize()) { if (!mBluetoothLeService.initialize()) {
Log.e(TAG, "Unable to initialize Bluetooth"); Log.e(TAG, "Unable to initialize Bluetooth");
@@ -92,7 +92,7 @@ public class DeviceControlActivity extends Activity {
} }
@Override @Override
public void onServiceDisconnected(ComponentName componentName) { public void onServiceDisconnected(final ComponentName componentName) {
mBluetoothLeService = null; mBluetoothLeService = null;
} }
}; };
@@ -105,7 +105,7 @@ public class DeviceControlActivity extends Activity {
// this can be a result of read or notification operations. // this can be a result of read or notification operations.
private final BroadcastReceiver mGattUpdateReceiver = new BroadcastReceiver() { private final BroadcastReceiver mGattUpdateReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(final Context context, final Intent intent) {
final String action = intent.getAction(); final String action = intent.getAction();
if (BluetoothLeService.ACTION_GATT_CONNECTED.equals(action)) { if (BluetoothLeService.ACTION_GATT_CONNECTED.equals(action)) {
mConnected = true; mConnected = true;
@@ -138,7 +138,7 @@ public class DeviceControlActivity extends Activity {
// list of supported characteristic features. // list of supported characteristic features.
private final ExpandableListView.OnChildClickListener servicesListClickListner = new ExpandableListView.OnChildClickListener() { private final ExpandableListView.OnChildClickListener servicesListClickListner = new ExpandableListView.OnChildClickListener() {
@Override @Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { public boolean onChildClick(final ExpandableListView parent, final View v, final int groupPosition, final int childPosition, final long id) {
if (mGattCharacteristics != null) { if (mGattCharacteristics != null) {
final BluetoothGattCharacteristic characteristic = mGattCharacteristics.get(groupPosition).get(childPosition); final BluetoothGattCharacteristic characteristic = mGattCharacteristics.get(groupPosition).get(childPosition);
final int charaProp = characteristic.getProperties(); final int charaProp = characteristic.getProperties();
@@ -169,7 +169,7 @@ public class DeviceControlActivity extends Activity {
mDataAsString.setText(R.string.no_data); mDataAsString.setText(R.string.no_data);
} }
private void generateExportString(List<BluetoothGattService> gattServices){ private void generateExportString(final List<BluetoothGattService> gattServices){
final String unknownServiceString = getResources().getString(R.string.unknown_service); final String unknownServiceString = getResources().getString(R.string.unknown_service);
final String unknownCharaString = getResources().getString(R.string.unknown_characteristic); final String unknownCharaString = getResources().getString(R.string.unknown_characteristic);
final StringBuilder exportBuilder = new StringBuilder(); final StringBuilder exportBuilder = new StringBuilder();
@@ -187,7 +187,7 @@ public class DeviceControlActivity extends Activity {
exportBuilder.append('\n'); exportBuilder.append('\n');
String uuid = null; String uuid = null;
for (BluetoothGattService gattService : gattServices) { for (final BluetoothGattService gattService : gattServices) {
uuid = gattService.getUuid().toString(); uuid = gattService.getUuid().toString();
exportBuilder.append(GattAttributeResolver.getAttributeName(uuid, unknownServiceString)); exportBuilder.append(GattAttributeResolver.getAttributeName(uuid, unknownServiceString));
@@ -221,7 +221,7 @@ public class DeviceControlActivity extends Activity {
// Demonstrates how to iterate through the supported GATT Services/Characteristics. // Demonstrates how to iterate through the supported GATT Services/Characteristics.
// In this sample, we populate the data structure that is bound to the ExpandableListView // In this sample, we populate the data structure that is bound to the ExpandableListView
// on the UI. // on the UI.
private void displayGattServices(List<BluetoothGattService> gattServices) { private void displayGattServices(final List<BluetoothGattService> gattServices) {
if (gattServices == null) return; if (gattServices == null) return;
generateExportString(gattServices); generateExportString(gattServices);
@@ -233,7 +233,7 @@ public class DeviceControlActivity extends Activity {
mGattCharacteristics = new ArrayList<List<BluetoothGattCharacteristic>>(); mGattCharacteristics = new ArrayList<List<BluetoothGattCharacteristic>>();
// Loops through available GATT Services. // Loops through available GATT Services.
for (BluetoothGattService gattService : gattServices) { for (final BluetoothGattService gattService : gattServices) {
final Map<String, String> currentServiceData = new HashMap<String, String>(); final Map<String, String> currentServiceData = new HashMap<String, String>();
uuid = gattService.getUuid().toString(); uuid = gattService.getUuid().toString();
currentServiceData.put(LIST_NAME, GattAttributeResolver.getAttributeName(uuid, unknownServiceString)); currentServiceData.put(LIST_NAME, GattAttributeResolver.getAttributeName(uuid, unknownServiceString));
@@ -275,7 +275,7 @@ public class DeviceControlActivity extends Activity {
} }
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gatt_services); setContentView(R.layout.activity_gatt_services);
@@ -298,7 +298,7 @@ public class DeviceControlActivity extends Activity {
} }
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.gatt_services, menu); getMenuInflater().inflate(R.menu.gatt_services, menu);
if (mConnected) { if (mConnected) {
menu.findItem(R.id.menu_connect).setVisible(false); menu.findItem(R.id.menu_connect).setVisible(false);
@@ -325,7 +325,7 @@ public class DeviceControlActivity extends Activity {
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(final MenuItem item) {
switch(item.getItemId()) { switch(item.getItemId()) {
case R.id.menu_connect: case R.id.menu_connect:
mBluetoothLeService.connect(mDeviceAddress); mBluetoothLeService.connect(mDeviceAddress);
@@ -402,7 +402,7 @@ public class DeviceControlActivity extends Activity {
return intentFilter; return intentFilter;
} }
private static String tryString(String string, String fallback){ private static String tryString(final String string, final String fallback){
if(string == null){ if(string == null){
return fallback; return fallback;
} else{ } else{
@@ -28,7 +28,7 @@ public class DeviceDetailsActivity extends ListActivity{
private BluetoothLeDevice mDevice; private BluetoothLeDevice mDevice;
private void appendAdRecordView(MergeAdapter adapter, String title, AdRecord record){ private void appendAdRecordView(final MergeAdapter adapter, final String title, final AdRecord record){
final LinearLayout lt = (LinearLayout) getLayoutInflater().inflate(R.layout.list_item_view_adrecord, null); final LinearLayout lt = (LinearLayout) getLayoutInflater().inflate(R.layout.list_item_view_adrecord, null);
final TextView tvString = (TextView) lt.findViewById(R.id.data_as_string); final TextView tvString = (TextView) lt.findViewById(R.id.data_as_string);
final TextView tvArray = (TextView) lt.findViewById(R.id.data_as_array); final TextView tvArray = (TextView) lt.findViewById(R.id.data_as_array);
@@ -41,7 +41,7 @@ public class DeviceDetailsActivity extends ListActivity{
adapter.addView(lt); adapter.addView(lt);
} }
private void appendDeviceInfo(MergeAdapter adapter, BluetoothLeDevice device){ private void appendDeviceInfo(final MergeAdapter adapter, final BluetoothLeDevice device){
final LinearLayout lt = (LinearLayout) getLayoutInflater().inflate(R.layout.list_item_view_device_info, null); final LinearLayout lt = (LinearLayout) getLayoutInflater().inflate(R.layout.list_item_view_device_info, null);
final TextView tvName = (TextView) lt.findViewById(R.id.deviceName); final TextView tvName = (TextView) lt.findViewById(R.id.deviceName);
final TextView tvAddress = (TextView) lt.findViewById(R.id.deviceAddress); final TextView tvAddress = (TextView) lt.findViewById(R.id.deviceAddress);
@@ -56,7 +56,7 @@ public class DeviceDetailsActivity extends ListActivity{
adapter.addView(lt); adapter.addView(lt);
} }
private void appendHeader(MergeAdapter adapter, String title){ private void appendHeader(final MergeAdapter adapter, final String title){
final LinearLayout lt = (LinearLayout) getLayoutInflater().inflate(R.layout.list_item_view_header, null); final LinearLayout lt = (LinearLayout) getLayoutInflater().inflate(R.layout.list_item_view_header, null);
final TextView tvTitle = (TextView) lt.findViewById(R.id.title); final TextView tvTitle = (TextView) lt.findViewById(R.id.title);
tvTitle.setText(title); tvTitle.setText(title);
@@ -64,7 +64,7 @@ public class DeviceDetailsActivity extends ListActivity{
adapter.addView(lt); adapter.addView(lt);
} }
private void appendIBeaconInfo(MergeAdapter adapter, IBeaconManufacturerData iBeaconData){ private void appendIBeaconInfo(final MergeAdapter adapter, final IBeaconManufacturerData iBeaconData){
final LinearLayout lt = (LinearLayout) getLayoutInflater().inflate(R.layout.list_item_view_ibeacon_details, null); final LinearLayout lt = (LinearLayout) getLayoutInflater().inflate(R.layout.list_item_view_ibeacon_details, null);
final TextView tvCompanyId = (TextView) lt.findViewById(R.id.companyId); final TextView tvCompanyId = (TextView) lt.findViewById(R.id.companyId);
final TextView tvAdvert = (TextView) lt.findViewById(R.id.advertisement); final TextView tvAdvert = (TextView) lt.findViewById(R.id.advertisement);
@@ -85,7 +85,7 @@ public class DeviceDetailsActivity extends ListActivity{
adapter.addView(lt); adapter.addView(lt);
} }
private void appendRssiInfo(MergeAdapter adapter, BluetoothLeDevice device){ private void appendRssiInfo(final MergeAdapter adapter, final BluetoothLeDevice device){
final LinearLayout lt = (LinearLayout) getLayoutInflater().inflate(R.layout.list_item_view_rssi_info, null); final LinearLayout lt = (LinearLayout) getLayoutInflater().inflate(R.layout.list_item_view_rssi_info, null);
final TextView tvFirstTimestamp = (TextView) lt.findViewById(R.id.firstTimestamp); final TextView tvFirstTimestamp = (TextView) lt.findViewById(R.id.firstTimestamp);
final TextView tvFirstRssi = (TextView) lt.findViewById(R.id.firstRssi); final TextView tvFirstRssi = (TextView) lt.findViewById(R.id.firstRssi);
@@ -102,11 +102,11 @@ public class DeviceDetailsActivity extends ListActivity{
adapter.addView(lt); adapter.addView(lt);
} }
private void appendSimpleText(MergeAdapter adapter, byte data[]){ private void appendSimpleText(final MergeAdapter adapter, final byte[] data){
appendSimpleText(adapter, ByteUtils.byteArrayToHexString(data)); appendSimpleText(adapter, ByteUtils.byteArrayToHexString(data));
} }
private void appendSimpleText(MergeAdapter adapter, String data){ private void appendSimpleText(final MergeAdapter adapter, final String data){
final LinearLayout lt = (LinearLayout) getLayoutInflater().inflate(R.layout.list_item_view_textview, null); final LinearLayout lt = (LinearLayout) getLayoutInflater().inflate(R.layout.list_item_view_textview, null);
final TextView tvData = (TextView) lt.findViewById(R.id.data); final TextView tvData = (TextView) lt.findViewById(R.id.data);
@@ -116,16 +116,16 @@ public class DeviceDetailsActivity extends ListActivity{
} }
private String formatRssi(double rssi){ private String formatRssi(final double rssi){
return getString(R.string.formatter_db, String.valueOf(rssi)); return getString(R.string.formatter_db, String.valueOf(rssi));
} }
private String formatRssi(int rssi){ private String formatRssi(final int rssi){
return getString(R.string.formatter_db, String.valueOf(rssi)); return getString(R.string.formatter_db, String.valueOf(rssi));
} }
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details); setContentView(R.layout.activity_details);
ButterKnife.inject(this); ButterKnife.inject(this);
@@ -136,13 +136,13 @@ public class DeviceDetailsActivity extends ListActivity{
} }
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.details, menu); getMenuInflater().inflate(R.menu.details, menu);
return true; return true;
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(final MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.menu_connect: case R.id.menu_connect:
@@ -156,7 +156,7 @@ public class DeviceDetailsActivity extends ListActivity{
return true; return true;
} }
private void pupulateDetails(BluetoothLeDevice device) { private void pupulateDetails(final BluetoothLeDevice device) {
final MergeAdapter adapter = new MergeAdapter(); final MergeAdapter adapter = new MergeAdapter();
if(device == null){ if(device == null){
@@ -196,11 +196,11 @@ public class DeviceDetailsActivity extends ListActivity{
getListView().setAdapter(adapter); getListView().setAdapter(adapter);
} }
private static String formatTime(long time){ private static String formatTime(final long time){
return TimeFormatter.getIsoDateTime(time); return TimeFormatter.getIsoDateTime(time);
} }
private static String hexEncode(int integer){ private static String hexEncode(final int integer){
return "0x" + Integer.toHexString(integer).toUpperCase(Locale.US); return "0x" + Integer.toHexString(integer).toUpperCase(Locale.US);
} }
} }
@@ -37,7 +37,7 @@ public class MainActivity extends ListActivity {
private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() { private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() {
@Override @Override
public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) { public void onLeScan(final BluetoothDevice device, final int rssi, final byte[] scanRecord) {
final BluetoothLeDevice deviceLe = new BluetoothLeDevice(device, rssi, scanRecord, System.currentTimeMillis()); final BluetoothLeDevice deviceLe = new BluetoothLeDevice(device, rssi, scanRecord, System.currentTimeMillis());
mDeviceStore.addDevice(deviceLe); mDeviceStore.addDevice(deviceLe);
@@ -53,7 +53,7 @@ public class MainActivity extends ListActivity {
} }
}; };
private void updateItemCount(int count){ private void updateItemCount(final int count){
mTvItemCount.setText( mTvItemCount.setText(
getString( getString(
R.string.formatter_item_count, R.string.formatter_item_count,
@@ -79,14 +79,14 @@ public class MainActivity extends ListActivity {
.setTitle(R.string.menu_about) .setTitle(R.string.menu_about)
.setCancelable(false) .setCancelable(false)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {} public void onClick(final DialogInterface dialog, final int id) {}
}) })
.setView(textView) .setView(textView)
.show(); .show();
} }
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
ButterKnife.inject(this); ButterKnife.inject(this);
@@ -98,7 +98,7 @@ public class MainActivity extends ListActivity {
} }
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.main, menu); getMenuInflater().inflate(R.menu.main, menu);
if (!mScanner.isScanning()) { if (!mScanner.isScanning()) {
menu.findItem(R.id.menu_stop).setVisible(false); menu.findItem(R.id.menu_stop).setVisible(false);
@@ -120,7 +120,7 @@ public class MainActivity extends ListActivity {
} }
@Override @Override
protected void onListItemClick(ListView l, View v, int position, long id) { protected void onListItemClick(final ListView l, final View v, final int position, final long id) {
final BluetoothLeDevice device = (BluetoothLeDevice) mLeDeviceListAdapter.getItem(position); final BluetoothLeDevice device = (BluetoothLeDevice) mLeDeviceListAdapter.getItem(position);
if (device == null) return; if (device == null) return;
@@ -132,7 +132,7 @@ public class MainActivity extends ListActivity {
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(final MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.menu_scan: case R.id.menu_scan:
startScan(); startScan();
@@ -18,7 +18,7 @@ public class LeDeviceListAdapter extends SimpleCursorAdapter {
private final LayoutInflater mInflator; private final LayoutInflater mInflator;
private final Activity mActivity; private final Activity mActivity;
public LeDeviceListAdapter(Activity activity, EasyObjectCursor<BluetoothLeDevice> cursor) { public LeDeviceListAdapter(final Activity activity, final EasyObjectCursor<BluetoothLeDevice> cursor) {
super(activity, R.layout.list_item_device, cursor, new String[0], new int[0], 0); super(activity, R.layout.list_item_device, cursor, new String[0], new int[0], 0);
mInflator = activity.getLayoutInflater(); mInflator = activity.getLayoutInflater();
mActivity = activity; mActivity = activity;
@@ -31,18 +31,18 @@ public class LeDeviceListAdapter extends SimpleCursorAdapter {
} }
@Override @Override
public BluetoothLeDevice getItem(int i){ public BluetoothLeDevice getItem(final int i){
return getCursor().getItem(i); return getCursor().getItem(i);
} }
@Override @Override
public long getItemId(int i) { public long getItemId(final int i) {
return i; return i;
} }
@Override @Override
public View getView(int i, View view, ViewGroup viewGroup) { public View getView(final int i, View view, final ViewGroup viewGroup) {
ViewHolder viewHolder; final ViewHolder viewHolder;
// General ListView optimization code. // General ListView optimization code.
if (view == null) { if (view == null) {
view = mInflator.inflate(R.layout.list_item_device, null); view = mInflator.inflate(R.layout.list_item_device, null);
@@ -31,7 +31,7 @@ public class BluetoothLeDeviceStore {
mDeviceMap = new HashMap<String, BluetoothLeDevice>(); mDeviceMap = new HashMap<String, BluetoothLeDevice>();
} }
public void addDevice(BluetoothLeDevice device){ public void addDevice(final BluetoothLeDevice device){
if(mDeviceMap.containsKey(device.getAddress())){ if(mDeviceMap.containsKey(device.getAddress())){
mDeviceMap.get(device.getAddress()).updateRssiReading(device.getTimestamp(), device.getRssi()); mDeviceMap.get(device.getAddress()).updateRssiReading(device.getTimestamp(), device.getRssi());
} else { } else {
@@ -44,19 +44,19 @@ public class BluetoothLeDeviceStore {
} }
private FileWriter generateFile(File file, String contents){ private FileWriter generateFile(final File file, final String contents){
FileWriter writer = null; FileWriter writer = null;
try { try {
writer = new FileWriter(file); writer = new FileWriter(file);
writer.append(contents); writer.append(contents);
writer.flush(); writer.flush();
} catch (IOException e) { } catch (final IOException e) {
e.printStackTrace(); e.printStackTrace();
}finally{ }finally{
try { try {
writer.close(); writer.close();
} catch (IOException e) { } catch (final IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@@ -76,7 +76,7 @@ public class BluetoothLeDeviceStore {
Collections.sort(methodResult, new Comparator<BluetoothLeDevice>() { Collections.sort(methodResult, new Comparator<BluetoothLeDevice>() {
@Override @Override
public int compare(BluetoothLeDevice arg0, BluetoothLeDevice arg1) { public int compare(final BluetoothLeDevice arg0, final BluetoothLeDevice arg1) {
return arg0.getAddress().compareToIgnoreCase(arg1.getAddress()); return arg0.getAddress().compareToIgnoreCase(arg1.getAddress());
} }
}); });
@@ -104,7 +104,7 @@ public class BluetoothLeDeviceStore {
sb.append(CsvWriterHelper.addStuff("accuracy")); sb.append(CsvWriterHelper.addStuff("accuracy"));
sb.append('\n'); sb.append('\n');
for(BluetoothLeDevice device : list){ for(final BluetoothLeDevice device : list){
sb.append(CsvWriterHelper.addStuff(device.getAddress())); sb.append(CsvWriterHelper.addStuff(device.getAddress()));
sb.append(CsvWriterHelper.addStuff(device.getName())); sb.append(CsvWriterHelper.addStuff(device.getName()));
sb.append(CsvWriterHelper.addStuff(TimeFormatter.getIsoDateTime(device.getFirstTimestamp()))); sb.append(CsvWriterHelper.addStuff(TimeFormatter.getIsoDateTime(device.getFirstTimestamp())));
@@ -152,7 +152,7 @@ public class BluetoothLeDeviceStore {
} }
public void shareDataAsEmail(Context context){ public void shareDataAsEmail(final Context context){
final long timeInMillis = System.currentTimeMillis(); final long timeInMillis = System.currentTimeMillis();
final String to = null; final String to = null;
@@ -175,7 +175,7 @@ public class BluetoothLeDeviceStore {
i.putExtra(Intent.EXTRA_TEXT, message); i.putExtra(Intent.EXTRA_TEXT, message);
context.startActivity(Intent.createChooser(i, context.getString(R.string.exporter_email_device_list_picker_text))); context.startActivity(Intent.createChooser(i, context.getString(R.string.exporter_email_device_list_picker_text)));
} catch (IOException e) { } catch (final IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@@ -61,8 +61,8 @@ public class BluetoothLeService extends Service {
// connection change and services discovered. // connection change and services discovered.
private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() { private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
@Override @Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { public void onConnectionStateChange(final BluetoothGatt gatt, final int status, final int newState) {
String intentAction; final String intentAction;
if (newState == BluetoothProfile.STATE_CONNECTED) { if (newState == BluetoothProfile.STATE_CONNECTED) {
intentAction = ACTION_GATT_CONNECTED; intentAction = ACTION_GATT_CONNECTED;
mConnectionState = STATE_CONNECTED; mConnectionState = STATE_CONNECTED;
@@ -80,7 +80,7 @@ public class BluetoothLeService extends Service {
} }
@Override @Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) { public void onServicesDiscovered(final BluetoothGatt gatt, final int status) {
if (status == BluetoothGatt.GATT_SUCCESS) { if (status == BluetoothGatt.GATT_SUCCESS) {
broadcastUpdate(ACTION_GATT_SERVICES_DISCOVERED); broadcastUpdate(ACTION_GATT_SERVICES_DISCOVERED);
} else { } else {
@@ -89,14 +89,14 @@ public class BluetoothLeService extends Service {
} }
@Override @Override
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { public void onCharacteristicRead(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic, final int status) {
if (status == BluetoothGatt.GATT_SUCCESS) { if (status == BluetoothGatt.GATT_SUCCESS) {
broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic); broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic);
} }
} }
@Override @Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { public void onCharacteristicChanged(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic) {
broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic); broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic);
} }
}; };
@@ -126,12 +126,12 @@ public class BluetoothLeService extends Service {
} }
@Override @Override
public IBinder onBind(Intent intent) { public IBinder onBind(final Intent intent) {
return mBinder; return mBinder;
} }
@Override @Override
public boolean onUnbind(Intent intent) { public boolean onUnbind(final Intent intent) {
// After using a given device, you should make sure that BluetoothGatt.close() is called // After using a given device, you should make sure that BluetoothGatt.close() is called
// such that resources are cleaned up properly. In this particular example, close() is // such that resources are cleaned up properly. In this particular example, close() is
// invoked when the UI is disconnected from the Service. // invoked when the UI is disconnected from the Service.
@@ -243,7 +243,7 @@ public class BluetoothLeService extends Service {
* *
* @param characteristic The characteristic to read from. * @param characteristic The characteristic to read from.
*/ */
public void readCharacteristic(BluetoothGattCharacteristic characteristic) { public void readCharacteristic(final BluetoothGattCharacteristic characteristic) {
if (mBluetoothAdapter == null || mBluetoothGatt == null) { if (mBluetoothAdapter == null || mBluetoothGatt == null) {
Log.w(TAG, "BluetoothAdapter not initialized"); Log.w(TAG, "BluetoothAdapter not initialized");
return; return;
@@ -257,7 +257,7 @@ public class BluetoothLeService extends Service {
* @param characteristic Characteristic to act on. * @param characteristic Characteristic to act on.
* @param enabled If true, enable notification. False otherwise. * @param enabled If true, enable notification. False otherwise.
*/ */
public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) { public void setCharacteristicNotification(final BluetoothGattCharacteristic characteristic, final boolean enabled) {
if (mBluetoothAdapter == null || mBluetoothGatt == null) { if (mBluetoothAdapter == null || mBluetoothGatt == null) {
Log.w(TAG, "BluetoothAdapter not initialized"); Log.w(TAG, "BluetoothAdapter not initialized");
return; return;
@@ -10,7 +10,7 @@ public class BluetoothLeScanner {
private final BluetoothUtils mBluetoothUtils; private final BluetoothUtils mBluetoothUtils;
private boolean mScanning; private boolean mScanning;
public BluetoothLeScanner(BluetoothAdapter.LeScanCallback leScanCallback, BluetoothUtils bluetoothUtils){ public BluetoothLeScanner(final BluetoothAdapter.LeScanCallback leScanCallback, final BluetoothUtils bluetoothUtils){
mHandler = new Handler(); mHandler = new Handler();
mLeScanCallback = leScanCallback; mLeScanCallback = leScanCallback;
mBluetoothUtils = bluetoothUtils; mBluetoothUtils = bluetoothUtils;
@@ -14,7 +14,7 @@ public final class BluetoothUtils {
public final static int REQUEST_ENABLE_BT = 2001; public final static int REQUEST_ENABLE_BT = 2001;
public BluetoothUtils(Activity activity){ public BluetoothUtils(final Activity activity){
mActivity = activity; mActivity = activity;
mBluetoothManager = (BluetoothManager) mActivity.getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothManager = (BluetoothManager) mActivity.getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter = mBluetoothManager.getAdapter(); mBluetoothAdapter = mBluetoothManager.getAdapter();
@@ -2,15 +2,15 @@ package uk.co.alt236.btlescan.util;
public class CsvWriterHelper { public class CsvWriterHelper {
private static final String QUOTE = "\""; private static final String QUOTE = "\"";
public static String addStuff(Integer text){ public static String addStuff(final Integer text){
return QUOTE + text + QUOTE + ","; return QUOTE + text + QUOTE + ",";
} }
public static String addStuff(Long text){ public static String addStuff(final Long text){
return QUOTE + text + QUOTE + ","; return QUOTE + text + QUOTE + ",";
} }
public static String addStuff(boolean value){ public static String addStuff(final boolean value){
return QUOTE + value + QUOTE + ","; return QUOTE + value + QUOTE + ",";
} }
@@ -8,11 +8,11 @@ public class TimeFormatter {
private final static String ISO_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS zzz"; private final static String ISO_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS zzz";
private final static SimpleDateFormat ISO_FORMATTER = new UtcDateFormatter(ISO_FORMAT, Locale.US); private final static SimpleDateFormat ISO_FORMATTER = new UtcDateFormatter(ISO_FORMAT, Locale.US);
public static String getIsoDateTime(Date date){ public static String getIsoDateTime(final Date date){
return ISO_FORMATTER.format(date); return ISO_FORMATTER.format(date);
} }
public static String getIsoDateTime(long millis){ public static String getIsoDateTime(final long millis){
return getIsoDateTime(new Date(millis)); return getIsoDateTime(new Date(millis));
} }
} }
@@ -42,18 +42,18 @@ public class UtcDateFormatter extends java.text.SimpleDateFormat{
private static final TimeZone TIME_ZONE_UTC = TimeZone.getTimeZone(TIME_ZONE_STRING); private static final TimeZone TIME_ZONE_UTC = TimeZone.getTimeZone(TIME_ZONE_STRING);
@SuppressLint("SimpleDateFormat") @SuppressLint("SimpleDateFormat")
public UtcDateFormatter(String template){ public UtcDateFormatter(final String template){
super(template); super(template);
super.setTimeZone(TIME_ZONE_UTC); super.setTimeZone(TIME_ZONE_UTC);
} }
@SuppressLint("SimpleDateFormat") @SuppressLint("SimpleDateFormat")
public UtcDateFormatter(String template, DateFormatSymbols symbols){ public UtcDateFormatter(final String template, final DateFormatSymbols symbols){
super(template, symbols); super(template, symbols);
super.setTimeZone(TIME_ZONE_UTC); super.setTimeZone(TIME_ZONE_UTC);
} }
public UtcDateFormatter(String template, Locale locale){ public UtcDateFormatter(final String template, final Locale locale){
super(template, locale); super(template, locale);
super.setTimeZone(TIME_ZONE_UTC); super.setTimeZone(TIME_ZONE_UTC);
} }
@@ -66,7 +66,7 @@ public class UtcDateFormatter extends java.text.SimpleDateFormat{
* @see java.text.DateFormat#setTimeZone(java.util.TimeZone) * @see java.text.DateFormat#setTimeZone(java.util.TimeZone)
*/ */
@Override @Override
public void setTimeZone(TimeZone timezone){ public void setTimeZone(final TimeZone timezone){
throw new UnsupportedOperationException("This SimpleDateFormat can only be in " + TIME_ZONE_STRING); throw new UnsupportedOperationException("This SimpleDateFormat can only be in " + TIME_ZONE_STRING);
} }
} }