1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-04 09:17:29 +01:00

Reformat code and optimize imports

This commit is contained in:
Andreas Shimokawa 2015-06-13 00:32:48 +02:00
parent ad4f708140
commit 56d314d054
12 changed files with 28 additions and 35 deletions

View File

@ -2,7 +2,6 @@ package nodomain.freeyourgadget.gadgetbridge;
import android.net.Uri;
import java.net.URI;
import java.util.UUID;
public interface EventHandler {

View File

@ -131,9 +131,10 @@ public class GBDevice implements Parcelable {
/**
* Marks the device as busy, performing a certain task. While busy, no other operations will
* be performed on the device.
*
* <p/>
* Note that nested busy tasks are not supported, every single call to #setBusyTask()
* or unsetBusy() has an effect.
*
* @param task a textual name of the task to be performed, possibly displayed to the user
*/
public void setBusyTask(String task) {

View File

@ -68,19 +68,19 @@ public interface GattCallback {
BluetoothGattCharacteristic characteristic);
/**
* @see BluetoothGattCallback#onDescriptorRead(BluetoothGatt, BluetoothGattDescriptor, int)
* @param gatt
* @param descriptor
* @param status
* @see BluetoothGattCallback#onDescriptorRead(BluetoothGatt, BluetoothGattDescriptor, int)
*/
public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor,
int status);
/**
* @see BluetoothGattCallback#onDescriptorWrite(BluetoothGatt, BluetoothGattDescriptor, int)
* @param gatt
* @param descriptor
* @param status
* @see BluetoothGattCallback#onDescriptorWrite(BluetoothGatt, BluetoothGattDescriptor, int)
*/
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor,
int status);

View File

@ -3,13 +3,10 @@ package nodomain.freeyourgadget.gadgetbridge.btle;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCallback;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import nodomain.freeyourgadget.gadgetbridge.miband.MiBandService;
/**
* Enables or disables notifications for a given GATT characteristic.
* The result will be made available asynchronously through the

View File

@ -1,7 +1,5 @@
package nodomain.freeyourgadget.gadgetbridge.btle;
import android.bluetooth.BluetoothGatt;
/**
* An abstract non-BTLE action. It performs no bluetooth operation,
* does not have a BluetoothGattCharacteristic instance and expects no result.

View File

@ -12,7 +12,8 @@ public class SetDeviceBusyAction extends PlainAction {
/**
* When run, will mark the device as busy (or not busy).
* @param device the device to mark
*
* @param device the device to mark
* @param busyTask the task name to set as busy task, or null to mark as not busy
* @param context
*/

View File

@ -5,8 +5,6 @@ import android.bluetooth.BluetoothGattCharacteristic;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import nodomain.freeyourgadget.gadgetbridge.miband.MiBandNotifyAction;
public class TransactionBuilder {
private static final Logger LOG = LoggerFactory.getLogger(TransactionBuilder.class);

View File

@ -44,6 +44,7 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper {
/**
* WITHOUT ROWID is only available with sqlite 3.8.2, which is available
* with Lollipop and later.
*
* @return the "WITHOUT ROWID" string or an empty string for pre-Lollipop devices
*/
private String getWithoutRowId() {
@ -55,7 +56,7 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper {
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (newVersion == 5 && (oldVersion == 4 || oldVersion ==3)) {
if (newVersion == 5 && (oldVersion == 4 || oldVersion == 3)) {
String CREATE_NEW_GBACTIVITYSAMPLES_TABLE = "CREATE TABLE NEW ("
+ KEY_TIMESTAMP + " INT,"
+ KEY_PROVIDER + " TINYINT,"
@ -64,8 +65,8 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper {
+ KEY_TYPE + " TINYINT,"
+ " PRIMARY KEY (" + KEY_TIMESTAMP + "," + KEY_PROVIDER + ") ON CONFLICT REPLACE)" + getWithoutRowId();
db.execSQL(CREATE_NEW_GBACTIVITYSAMPLES_TABLE);
db.execSQL("insert into NEW select timestamp,provider,intensity,steps,type from "+ TABLE_GBACTIVITYSAMPLES+";");
db.execSQL("Drop table "+TABLE_GBACTIVITYSAMPLES+";");
db.execSQL("insert into NEW select timestamp,provider,intensity,steps,type from " + TABLE_GBACTIVITYSAMPLES + ";");
db.execSQL("Drop table " + TABLE_GBACTIVITYSAMPLES + ";");
db.execSQL("alter table NEW RENAME TO " + TABLE_GBACTIVITYSAMPLES + ";");
} else {
//FIXME: do not just recreate

View File

@ -8,16 +8,14 @@ import android.bluetooth.BluetoothGattDescriptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import nodomain.freeyourgadget.gadgetbridge.btle.BtLEAction;
import nodomain.freeyourgadget.gadgetbridge.btle.NotifyAction;
import nodomain.freeyourgadget.gadgetbridge.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.miband.MiBandService;
/**
* Enables or disables notifications for a given GATT characteristic.
* The result will be made available asynchronously through the
* {@link BluetoothGattCallback}.
*
* <p/>
* This class is Mi Band specific.
*/
public class MiBandNotifyAction extends NotifyAction {

View File

@ -128,7 +128,7 @@ public class MiBandService {
public static final byte COMMAND_REBOOT = 0xc;
public static final byte COMMAND_SEND_NOTIFICATION = 0x8;
public static final byte COMMAND_STOP_MOTOR_VIBRATE = 0x13;
public static final byte COMMAND_CONFIRM_ACTIVITY_DATA_TRANSFER_COMPLETE = 0xa;

View File

@ -86,6 +86,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
* Last action of initialization sequence. Sets the device to initialized.
* It is only invoked if all other actions were successfully run, so the device
* must be initialized, then.
*
* @param builder
*/
private void setInitialized(TransactionBuilder builder) {
@ -150,10 +151,10 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
builder.queue(getQueue());
}
private static final byte[] startVibrate = new byte[] { MiBandService.COMMAND_SEND_NOTIFICATION, 1 };
private static final byte[] stopVibrate = new byte[] { MiBandService.COMMAND_STOP_MOTOR_VIBRATE };
private static final byte[] reboot = new byte[]{ MiBandService.COMMAND_REBOOT };
private static final byte[] fetch = new byte[]{ MiBandService.COMMAND_FETCH_DATA };
private static final byte[] startVibrate = new byte[]{MiBandService.COMMAND_SEND_NOTIFICATION, 1};
private static final byte[] stopVibrate = new byte[]{MiBandService.COMMAND_STOP_MOTOR_VIBRATE};
private static final byte[] reboot = new byte[]{MiBandService.COMMAND_REBOOT};
private static final byte[] fetch = new byte[]{MiBandService.COMMAND_FETCH_DATA};
private byte[] getNotification(long vibrateDuration, int vibrateTimes, int flashTimes, int flashColour, int originalColour, long flashDuration) {
byte[] vibrate = new byte[]{MiBandService.COMMAND_SEND_NOTIFICATION, (byte) 1};
@ -452,11 +453,11 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
}
private void handleActivityNotif(byte[] value) {
if (value.length == 11 ) {
if (value.length == 11) {
// byte 0 is the data type: 1 means that each minute is represented by a triplet of bytes
int dataType = value[0];
// byte 1 to 6 represent a timestamp
GregorianCalendar timestamp = new GregorianCalendar(value[1]+2000,
GregorianCalendar timestamp = new GregorianCalendar(value[1] + 2000,
value[2],
value[3],
value[4],
@ -470,15 +471,15 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
// counter of this data block
int dataUntilNextHeader = (value[9] & 0xff) | ((value[10] & 0xff) << 8);
dataUntilNextHeader *= (dataType ==1) ? 3 : 1;
dataUntilNextHeader *= (dataType == 1) ? 3 : 1;
// there is a total of totalDataToRead that will come in chunks (3 bytes per minute if dataType == 1),
// these chunks are usually 20 bytes long and grouped in blocks
// after dataUntilNextHeader bytes we will get a new packet of 11 bytes that should be parsed
// as we just did
LOG.info("total data to read: "+ totalDataToRead +" len: " + (totalDataToRead / 3) + " minute(s)");
LOG.info("data to read until next header: "+ dataUntilNextHeader +" len: " + (dataUntilNextHeader / 3) + " minute(s)");
LOG.info("total data to read: " + totalDataToRead + " len: " + (totalDataToRead / 3) + " minute(s)");
LOG.info("data to read until next header: " + dataUntilNextHeader + " len: " + (dataUntilNextHeader / 3) + " minute(s)");
LOG.info("TIMESTAMP: " + DateFormat.getDateTimeInstance().format(timestamp.getTime()).toString() + " magic byte: " + dataUntilNextHeader);
this.activityDataRemainingBytes = this.activityDataUntilNextHeader = dataUntilNextHeader;
@ -499,7 +500,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
//I don't like this clause, but until we figure out why we get different data sometimes this should work
if (value.length == 20 || value.length == this.activityDataRemainingBytes) {
System.arraycopy(value, 0, this.activityDataHolder, this.activityDataHolderProgress, value.length);
this.activityDataHolderProgress +=value.length;
this.activityDataHolderProgress += value.length;
this.activityDataRemainingBytes -= value.length;
if (this.activityDataHolderSize == this.activityDataHolderProgress) {
@ -508,7 +509,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
} else {
// the length of the chunk is not what we expect. We need to make sense of this data
LOG.warn("GOT UNEXPECTED ACTIVITY DATA WITH LENGTH: " + value.length + ", EXPECTED LENGTH: " + this.activityDataRemainingBytes);
for (byte b: value){
for (byte b : value) {
LOG.warn("DATA: " + String.format("0x%8x", b));
}
}
@ -521,10 +522,10 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
ActivityDatabaseHandler dbHandler = GBApplication.getActivityDatabaseHandler();
try (SQLiteDatabase db = dbHandler.getWritableDatabase()) { // explicitly keep the db open while looping over the samples
for (int i=0; i<this.activityDataHolderProgress; i+=3) { //TODO: check if multiple of 3, if not something is wrong
for (int i = 0; i < this.activityDataHolderProgress; i += 3) { //TODO: check if multiple of 3, if not something is wrong
category = this.activityDataHolder[i];
intensity = this.activityDataHolder[i+1];
steps = this.activityDataHolder[i+2];
intensity = this.activityDataHolder[i + 1];
steps = this.activityDataHolder[i + 2];
dbHandler.addGBActivitySample(
(int) (timestamp.getTimeInMillis() / 1000),
@ -551,7 +552,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
unsetBusy();
}
}
for (byte b: value){
for (byte b : value) {
LOG.info("handleControlPoint GOT DATA:" + String.format("0x%8x", b));
}
}

View File

@ -4,7 +4,6 @@ import android.bluetooth.BluetoothGatt;
import android.content.Context;
import nodomain.freeyourgadget.gadgetbridge.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.btle.BtLEAction;
import nodomain.freeyourgadget.gadgetbridge.btle.PlainAction;
public class SetDeviceStateAction extends PlainAction {