reformat code

live-activity-data 0.4.4
Andreas Shimokawa 2015-07-25 21:52:52 +02:00
parent c4590d3989
commit dbbcf20bbc
17 changed files with 53 additions and 49 deletions

View File

@ -176,9 +176,10 @@ public class GB {
* Creates and display a Toast message using the application context.
* Additionally the toast is logged using the provided severity.
* Can be called from any thread.
* @param message the message to display.
*
* @param message the message to display.
* @param displayTime something like Toast.LENGTH_SHORT
* @param severity either INFO, WARNING, ERROR
* @param severity either INFO, WARNING, ERROR
*/
public static void toast(String message, int displayTime, int severity) {
toast(GBApplication.getContext(), message, displayTime, severity, null);
@ -188,9 +189,10 @@ public class GB {
* Creates and display a Toast message using the application context.
* Additionally the toast is logged using the provided severity.
* Can be called from any thread.
* @param message the message to display.
*
* @param message the message to display.
* @param displayTime something like Toast.LENGTH_SHORT
* @param severity either INFO, WARNING, ERROR
* @param severity either INFO, WARNING, ERROR
*/
public static void toast(String message, int displayTime, int severity, Throwable ex) {
toast(GBApplication.getContext(), message, displayTime, severity, ex);
@ -199,23 +201,25 @@ public class GB {
/**
* Creates and display a Toast message using the application context
* Can be called from any thread.
* @param context the context to use
* @param message the message to display
*
* @param context the context to use
* @param message the message to display
* @param displayTime something like Toast.LENGTH_SHORT
* @param severity either INFO, WARNING, ERROR
* @param severity either INFO, WARNING, ERROR
*/
public static void toast(final Context context, final String message, final int displayTime, final int severity) {
toast(context, message, displayTime, severity, null);
toast(context, message, displayTime, severity, null);
}
/**
* Creates and display a Toast message using the application context
* Can be called from any thread.
* @param context the context to use
* @param message the message to display
*
* @param context the context to use
* @param message the message to display
* @param displayTime something like Toast.LENGTH_SHORT
* @param severity either INFO, WARNING, ERROR
* @param ex optional exception to be logged
* @param severity either INFO, WARNING, ERROR
* @param ex optional exception to be logged
*/
public static void toast(final Context context, final String message, final int displayTime, final int severity, final Throwable ex) {
Looper mainLooper = Looper.getMainLooper();

View File

@ -24,7 +24,6 @@ import nodomain.freeyourgadget.gadgetbridge.GBActivitySample;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.charts.ActivityKind;
import nodomain.freeyourgadget.gadgetbridge.charts.SleepUtils;
public abstract class AbstractChartFragment extends Fragment {
@ -62,7 +61,7 @@ public abstract class AbstractChartFragment extends Fragment {
case nodomain.freeyourgadget.gadgetbridge.charts.ActivityKind.TYPE_LIGHT_SLEEP:
return akLightSleep.color;
case nodomain.freeyourgadget.gadgetbridge.charts.ActivityKind.TYPE_ACTIVITY:
return akActivity.color;
return akActivity.color;
}
return akActivity.color;
}
@ -290,7 +289,7 @@ public abstract class AbstractChartFragment extends Fragment {
protected abstract void setupLegend(Chart chart);
protected BarEntry createBarEntry(float value, int index) {
protected BarEntry createBarEntry(float value, int index) {
return new BarEntry(value, index);
}

View File

@ -1,6 +1,5 @@
package nodomain.freeyourgadget.gadgetbridge.activities;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@ -13,13 +12,10 @@ import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.TextView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -126,7 +122,7 @@ public class ChartsActivity extends FragmentActivity {
startService(startIntent);
return true;
default:
break;
break;
}
return super.onOptionsItemSelected(item);

View File

@ -23,7 +23,6 @@ import com.github.mikephil.charting.utils.ValueFormatter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
@ -97,7 +96,7 @@ public class SleepChartFragment extends AbstractChartFragment {
set.setValueFormatter(new ValueFormatter() {
@Override
public String getFormattedValue(float value) {
return GB.formatDurationHoursMinutes((long)value, TimeUnit.SECONDS);
return GB.formatDurationHoursMinutes((long) value, TimeUnit.SECONDS);
}
});
set.setColors(colors);

View File

@ -5,7 +5,6 @@ import android.bluetooth.BluetoothGattCharacteristic;
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
/**
* The Bluedroid implementation only allows performing one GATT request at a time.

View File

@ -188,7 +188,7 @@ public final class BtLEQueue {
// To support automatic reconnection, we keep the mBluetoothGatt instance
// alive (we do not close() it). Unfortunately we sometimes have problems
// reconnecting automatically, so we try to fix this by re-creating mBluetoothGatt.
if (status != 0 ) {
if (status != 0) {
maybeReconnect();
}
}

View File

@ -1,6 +1,5 @@
package nodomain.freeyourgadget.gadgetbridge.charts;
import java.util.ArrayList;
import java.util.List;
import nodomain.freeyourgadget.gadgetbridge.GBActivitySample;
@ -13,7 +12,7 @@ public class ActivityAnalysis {
ActivityAmount previousAmount = null;
GBActivitySample previousSample = null;
for(GBActivitySample sample : samples) {
for (GBActivitySample sample : samples) {
ActivityAmount amount = null;
switch (sample.getType()) {
case GBActivitySample.TYPE_DEEP_SLEEP:

View File

@ -11,7 +11,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Arrays;
import nodomain.freeyourgadget.gadgetbridge.GB;
import nodomain.freeyourgadget.gadgetbridge.GBActivitySample;
@ -132,9 +131,10 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper {
/**
* Returns all available activity samples from between the two timestamps (inclusive), of the given
* provided and type(s).
*
* @param timestamp_from
* @param timestamp_to
* @param activityTypes ORed combination of #TYPE_DEEP_SLEEP, #TYPE_LIGHT_SLEEP, #TYPE_ACTIVITY
* @param activityTypes ORed combination of #TYPE_DEEP_SLEEP, #TYPE_LIGHT_SLEEP, #TYPE_ACTIVITY
* @param provider
* @return
*/
@ -143,7 +143,7 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper {
timestamp_to = Integer.MAX_VALUE; // dont know what happens when I use more than max of a signed int
}
ArrayList<GBActivitySample> GBActivitySampleList = new ArrayList<GBActivitySample>();
final String where = "(provider=" + provider + " and timestamp>=" + timestamp_from + " and timestamp<=" + timestamp_to + getWhereClauseFor(activityTypes) +")";
final String where = "(provider=" + provider + " and timestamp>=" + timestamp_from + " and timestamp<=" + timestamp_to + getWhereClauseFor(activityTypes) + ")";
final String order = "timestamp";
try (SQLiteDatabase db = this.getReadableDatabase()) {
Cursor cursor = db.query(TABLE_GBACTIVITYSAMPLES, null, where, null, null, null, order);

View File

@ -6,7 +6,6 @@ import android.database.sqlite.SQLiteOpenHelper;
import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

View File

@ -7,10 +7,11 @@ import android.database.sqlite.SQLiteDatabase;
* Implementors provide the update from the prior schema
* version to this version, and the downgrade from this schema
* version to the next lower version.
*
* <p/>
* Implementations must have a public, no-arg constructor.
*/
public interface DBUpdateScript {
void upgradeSchema(SQLiteDatabase database);
void downgradeSchema(SQLiteDatabase database);
}

View File

@ -3,9 +3,13 @@ package nodomain.freeyourgadget.gadgetbridge.database.schema;
import android.database.sqlite.SQLiteDatabase;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.database.DBUpdateScript;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.*;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_INTENSITY;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_PROVIDER;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_STEPS;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_TIMESTAMP;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_TYPE;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.TABLE_GBACTIVITYSAMPLES;
public class ActivityDBCreationScript {
public void createSchema(SQLiteDatabase db) {

View File

@ -6,7 +6,6 @@ import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.database.DBUpdateScript;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.TABLE_GBACTIVITYSAMPLES;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.TABLE_STEPS_PER_DAY;
/**
* Upgrade and downgrade with DB versions <= 5 is not supported.

View File

@ -5,7 +5,10 @@ import android.database.sqlite.SQLiteDatabase;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.database.DBUpdateScript;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.*;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_PROVIDER;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_STEPS;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_TIMESTAMP;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.TABLE_STEPS_PER_DAY;
/**
* Adds a table "STEPS_PER_DAY".

View File

@ -9,7 +9,6 @@ import org.slf4j.LoggerFactory;
import java.util.Calendar;
import nodomain.freeyourgadget.gadgetbridge.AppManagerActivity;
import nodomain.freeyourgadget.gadgetbridge.DeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.DeviceType;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;

View File

@ -66,14 +66,15 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
//index of the buffer above
public int activityDataHolderProgress = 0;
//number of bytes we will get in a single data transfer, used as counter
public int activityDataRemainingBytes = 0;
public int activityDataRemainingBytes = 0;
//same as above, but remains untouched for the ack message
public int activityDataUntilNextHeader = 0;
public int activityDataUntilNextHeader = 0;
//timestamp of the single data transfer, incremented to store each minute's data
public GregorianCalendar activityDataTimestampProgress = null;
public GregorianCalendar activityDataTimestampProgress = null;
//same as above, but remains untouched for the ack message
public GregorianCalendar activityDataTimestampToAck = null;
}
private static final Logger LOG = LoggerFactory.getLogger(MiBandSupport.class);
private volatile boolean telephoneRinging;
private volatile boolean isLocatingDevice;
@ -503,18 +504,18 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
private byte[] getLatency(int minConnectionInterval, int maxConnectionInterval, int latency, int timeout, int advertisementInterval) {
byte result[] = new byte[12];
result[0] = (byte)(minConnectionInterval & 0xff);
result[1] = (byte)(0xff & minConnectionInterval >> 8);
result[2] = (byte)(maxConnectionInterval & 0xff);
result[0] = (byte) (minConnectionInterval & 0xff);
result[1] = (byte) (0xff & minConnectionInterval >> 8);
result[2] = (byte) (maxConnectionInterval & 0xff);
result[3] = (byte) (0xff & maxConnectionInterval >> 8);
result[4] = (byte)(latency & 0xff);
result[5] = (byte)(0xff & latency >> 8);
result[6] = (byte)(timeout & 0xff);
result[4] = (byte) (latency & 0xff);
result[5] = (byte) (0xff & latency >> 8);
result[6] = (byte) (timeout & 0xff);
result[7] = (byte) (0xff & timeout >> 8);
result[8] = 0;
result[9] = 0;
result[10] = (byte)(advertisementInterval & 0xff);
result[11] = (byte)(0xff & advertisementInterval >> 8);
result[10] = (byte) (advertisementInterval & 0xff);
result[11] = (byte) (0xff & advertisementInterval >> 8);
return result;
}
@ -780,7 +781,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
//The last data chunk sent by the miband has always length 0.
//When we ack this chunk, the transfer is done.
if(getDevice().isBusy() && bytesTransferred==0) {
if (getDevice().isBusy() && bytesTransferred == 0) {
handleActivityFetchFinish();
}
} catch (IOException ex) {

View File

@ -36,7 +36,7 @@ public class GadgetbridgePblSupport {
break;
case KEY_SAMPLES:
byte[] samples = (byte[]) pair.second;
LOG.info("got " + samples.length/2 + " samples");
LOG.info("got " + samples.length / 2 + " samples");
ByteBuffer samplesBuffer = ByteBuffer.wrap(samples);
// TODO: read samples and put into database
break;

View File

@ -11,6 +11,7 @@ import nodomain.freeyourgadget.gadgetbridge.GBApplication;
public class FileUtils {
/**
* Copies the the given sourceFile to destFile, overwriting it, in case it exists.
*
* @param sourceFile
* @param destFile
* @throws IOException
@ -30,6 +31,7 @@ public class FileUtils {
/**
* Returns the existing external storage dir.
*
* @throws IOException when the directory is not available
*/
public static File getExternalFilesDir() throws IOException {