mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-11 17:41:57 +01:00
Merge branch 'master' into background-javascript
This commit is contained in:
commit
181b33d6be
@ -86,13 +86,13 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
|
|||||||
for (int counter = 0; counter < 7; counter++) {
|
for (int counter = 0; counter < 7; counter++) {
|
||||||
ActivityAmounts amounts = getActivityAmountsForDay(db, day, device);
|
ActivityAmounts amounts = getActivityAmountsForDay(db, day, device);
|
||||||
|
|
||||||
entries.add(new BarEntry(counter, getTotalForActivityAmounts(amounts)));
|
entries.add(new BarEntry(counter, getTotalsForActivityAmounts(amounts)));
|
||||||
labels.add(day.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, mLocale));
|
labels.add(day.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, mLocale));
|
||||||
day.add(Calendar.DATE, 1);
|
day.add(Calendar.DATE, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
BarDataSet set = new BarDataSet(entries, "");
|
BarDataSet set = new BarDataSet(entries, "");
|
||||||
set.setColor(getMainColor());
|
set.setColors(getColors());
|
||||||
set.setValueFormatter(getFormatter());
|
set.setValueFormatter(getFormatter());
|
||||||
|
|
||||||
BarData barData = new BarData(set);
|
BarData barData = new BarData(set);
|
||||||
@ -106,29 +106,32 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private DayData refreshDayPie(DBHandler db, Calendar day, GBDevice device) {
|
private DayData refreshDayPie(DBHandler db, Calendar day, GBDevice device) {
|
||||||
ActivityAmounts amounts = getActivityAmountsForDay(db, day, device);
|
|
||||||
int totalValue = getTotalForActivityAmounts(amounts);
|
|
||||||
|
|
||||||
PieData data = new PieData();
|
PieData data = new PieData();
|
||||||
List<PieEntry> entries = new ArrayList<>();
|
List<PieEntry> entries = new ArrayList<>();
|
||||||
List<Integer> colors = new ArrayList<>();
|
PieDataSet set = new PieDataSet(entries, "");
|
||||||
|
|
||||||
entries.add(new PieEntry(totalValue, "")); //we don't want labels on the pie chart
|
ActivityAmounts amounts = getActivityAmountsForDay(db, day, device);
|
||||||
colors.add(getMainColor());
|
float totalValues[] = getTotalsForActivityAmounts(amounts);
|
||||||
|
float totalValue = 0;
|
||||||
if (totalValue < mTargetValue) {
|
for (float value : totalValues) {
|
||||||
entries.add(new PieEntry((mTargetValue - totalValue))); //we don't want labels on the pie chart
|
totalValue += value;
|
||||||
colors.add(Color.GRAY);
|
entries.add(new PieEntry(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
PieDataSet set = new PieDataSet(entries, "");
|
|
||||||
set.setValueFormatter(getFormatter());
|
set.setValueFormatter(getFormatter());
|
||||||
set.setColors(colors);
|
set.setColors(getColors());
|
||||||
|
|
||||||
|
if (totalValue < mTargetValue) {
|
||||||
|
entries.add(new PieEntry((mTargetValue - totalValue)));
|
||||||
|
set.addColor(Color.GRAY);
|
||||||
|
}
|
||||||
|
|
||||||
data.setDataSet(set);
|
data.setDataSet(set);
|
||||||
//this hides the values (numeric) added to the set. These would be shown aside the strings set with addXValue above
|
//this hides the values (numeric) added to the set. These would be shown aside the strings set with addXValue above
|
||||||
data.setDrawValues(false);
|
data.setDrawValues(false);
|
||||||
|
|
||||||
return new DayData(data, formatPieValue(totalValue));
|
return new DayData(data, formatPieValue((int) totalValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract String formatPieValue(int value);
|
protected abstract String formatPieValue(int value);
|
||||||
@ -286,9 +289,9 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
|
|||||||
|
|
||||||
abstract int getGoal();
|
abstract int getGoal();
|
||||||
|
|
||||||
abstract int getTotalForActivityAmounts(ActivityAmounts activityAmounts);
|
abstract float[] getTotalsForActivityAmounts(ActivityAmounts activityAmounts);
|
||||||
|
|
||||||
abstract IValueFormatter getFormatter();
|
abstract IValueFormatter getFormatter();
|
||||||
|
|
||||||
abstract Integer getMainColor();
|
abstract int[] getColors();
|
||||||
}
|
}
|
||||||
|
@ -24,14 +24,17 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
int getTotalForActivityAmounts(ActivityAmounts activityAmounts) {
|
float[] getTotalsForActivityAmounts(ActivityAmounts activityAmounts) {
|
||||||
long totalSeconds = 0;
|
long totalSecondsDeepSleep = 0;
|
||||||
|
long totalSecondsLightSleep = 0;
|
||||||
for (ActivityAmount amount : activityAmounts.getAmounts()) {
|
for (ActivityAmount amount : activityAmounts.getAmounts()) {
|
||||||
if ((amount.getActivityKind() & ActivityKind.TYPE_SLEEP) != 0) {
|
if (amount.getActivityKind() == ActivityKind.TYPE_DEEP_SLEEP) {
|
||||||
totalSeconds += amount.getTotalSeconds();
|
totalSecondsDeepSleep += amount.getTotalSeconds();
|
||||||
|
} else if (amount.getActivityKind() == ActivityKind.TYPE_LIGHT_SLEEP) {
|
||||||
|
totalSecondsLightSleep += amount.getTotalSeconds();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (int) (totalSeconds / 60);
|
return new float[]{(int) (totalSecondsDeepSleep / 60), (int) (totalSecondsLightSleep / 60)};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -50,7 +53,7 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Integer getMainColor() {
|
int[] getColors() {
|
||||||
return akLightSleep.color;
|
return new int[]{akDeepSleep.color, akLightSleep.color};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,13 +24,13 @@ public class WeekStepsChartFragment extends AbstractWeekChartFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
int getTotalForActivityAmounts(ActivityAmounts activityAmounts) {
|
float[] getTotalsForActivityAmounts(ActivityAmounts activityAmounts) {
|
||||||
int totalSteps = 0;
|
int totalSteps = 0;
|
||||||
for (ActivityAmount amount : activityAmounts.getAmounts()) {
|
for (ActivityAmount amount : activityAmounts.getAmounts()) {
|
||||||
totalSteps += amount.getTotalSteps();
|
totalSteps += amount.getTotalSteps();
|
||||||
amount.getTotalSteps();
|
amount.getTotalSteps();
|
||||||
}
|
}
|
||||||
return totalSteps;
|
return new float[]{totalSteps};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -44,7 +44,7 @@ public class WeekStepsChartFragment extends AbstractWeekChartFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Integer getMainColor() {
|
int[] getColors() {
|
||||||
return akActivity.color;
|
return new int[]{akActivity.color};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,18 +45,7 @@ public class DeviceCandidateAdapter extends ArrayAdapter<GBDeviceCandidate> {
|
|||||||
String name = formatDeviceCandidate(device);
|
String name = formatDeviceCandidate(device);
|
||||||
deviceNameLabel.setText(name);
|
deviceNameLabel.setText(name);
|
||||||
deviceAddressLabel.setText(device.getMacAddress());
|
deviceAddressLabel.setText(device.getMacAddress());
|
||||||
|
deviceImageView.setImageResource(device.getDeviceType().getIcon());
|
||||||
switch (device.getDeviceType()) {
|
|
||||||
case PEBBLE:
|
|
||||||
deviceImageView.setImageResource(R.drawable.ic_device_pebble);
|
|
||||||
break;
|
|
||||||
case MIBAND:
|
|
||||||
case MIBAND2:
|
|
||||||
deviceImageView.setImageResource(R.drawable.ic_device_miband);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
deviceImageView.setImageResource(R.drawable.ic_launcher);
|
|
||||||
}
|
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
@ -111,43 +111,10 @@ public class GBDeviceAdapter extends ArrayAdapter<GBDevice> {
|
|||||||
batteryStatusLabel.setText("");
|
batteryStatusLabel.setText("");
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (device.getType()) {
|
|
||||||
case PEBBLE:
|
|
||||||
if (device.isConnected()) {
|
if (device.isConnected()) {
|
||||||
deviceImageView.setImageResource(R.drawable.ic_device_pebble);
|
deviceImageView.setImageResource(device.getType().getIcon());
|
||||||
} else {
|
} else {
|
||||||
deviceImageView.setImageResource(R.drawable.ic_device_pebble_disabled);
|
deviceImageView.setImageResource(device.getType().getDisabledIcon());
|
||||||
}
|
|
||||||
break;
|
|
||||||
case MIBAND:
|
|
||||||
case MIBAND2:
|
|
||||||
if (device.isConnected()) {
|
|
||||||
deviceImageView.setImageResource(R.drawable.ic_device_miband);
|
|
||||||
} else {
|
|
||||||
deviceImageView.setImageResource(R.drawable.ic_device_miband_disabled);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case VIBRATISSIMO:
|
|
||||||
if (device.isConnected()) {
|
|
||||||
deviceImageView.setImageResource(R.drawable.ic_device_lovetoy);
|
|
||||||
} else {
|
|
||||||
deviceImageView.setImageResource(R.drawable.ic_device_lovetoy_disabled);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case HPLUS:
|
|
||||||
case MAKIBESF68:
|
|
||||||
if( device.isConnected()) {
|
|
||||||
deviceImageView.setImageResource(R.drawable.ic_device_hplus);
|
|
||||||
} else {
|
|
||||||
deviceImageView.setImageResource(R.drawable.ic_device_hplus_disabled);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (device.isConnected()) {
|
|
||||||
deviceImageView.setImageResource(R.drawable.ic_launcher);
|
|
||||||
} else {
|
|
||||||
deviceImageView.setImageResource(R.drawable.ic_device_default_disabled);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
|
@ -6,7 +6,9 @@ import android.bluetooth.le.ScanFilter;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.support.annotation.DrawableRes;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@ -83,18 +85,20 @@ public interface DeviceCoordinator {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Activity class to be started in order to perform a pairing of a
|
* Returns the Activity class to be started in order to perform a pairing of a
|
||||||
* given device.
|
* given device after its discovery.
|
||||||
*
|
*
|
||||||
* @return
|
* @return the activity class for pairing/initial authentication, or null if none
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
Class<? extends Activity> getPairingActivity();
|
Class<? extends Activity> getPairingActivity();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Activity class that will be used as the primary activity
|
* Returns the Activity class that will be used as the primary activity
|
||||||
* for the given device.
|
* for the given device.
|
||||||
*
|
*
|
||||||
* @return
|
* @return the primary activity class, or null if none
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
Class<? extends Activity> getPrimaryActivity();
|
Class<? extends Activity> getPrimaryActivity();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.model;
|
package nodomain.freeyourgadget.gadgetbridge.model;
|
||||||
|
|
||||||
|
import android.support.annotation.DrawableRes;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For every supported device, a device type constant must exist.
|
* For every supported device, a device type constant must exist.
|
||||||
*
|
*
|
||||||
@ -7,20 +11,26 @@ package nodomain.freeyourgadget.gadgetbridge.model;
|
|||||||
* and may not be changed.
|
* and may not be changed.
|
||||||
*/
|
*/
|
||||||
public enum DeviceType {
|
public enum DeviceType {
|
||||||
UNKNOWN(-1),
|
UNKNOWN(-1, R.drawable.ic_launcher, R.drawable.ic_device_default_disabled),
|
||||||
PEBBLE(1),
|
PEBBLE(1, R.drawable.ic_device_pebble, R.drawable.ic_device_pebble_disabled),
|
||||||
MIBAND(10),
|
MIBAND(10, R.drawable.ic_device_miband, R.drawable.ic_device_miband_disabled),
|
||||||
MIBAND2(11),
|
MIBAND2(11, R.drawable.ic_device_miband, R.drawable.ic_device_miband_disabled),
|
||||||
VIBRATISSIMO(20),
|
VIBRATISSIMO(20, R.drawable.ic_device_lovetoy, R.drawable.ic_device_lovetoy_disabled),
|
||||||
LIVEVIEW(30),
|
LIVEVIEW(30, R.drawable.ic_launcher, R.drawable.ic_device_default_disabled),
|
||||||
HPLUS(40),
|
HPLUS(40, R.drawable.ic_device_hplus, R.drawable.ic_device_hplus_disabled),
|
||||||
MAKIBESF68(41),
|
MAKIBESF68(41, R.drawable.ic_device_hplus, R.drawable.ic_device_hplus_disabled),
|
||||||
TEST(1000);
|
TEST(1000, R.drawable.ic_launcher, R.drawable.ic_device_default_disabled);
|
||||||
|
|
||||||
private final int key;
|
private final int key;
|
||||||
|
@DrawableRes
|
||||||
|
private final int defaultIcon;
|
||||||
|
@DrawableRes
|
||||||
|
private final int disabledIcon;
|
||||||
|
|
||||||
DeviceType(int key) {
|
DeviceType(int key, int defaultIcon, int disabledIcon) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
|
this.defaultIcon = defaultIcon;
|
||||||
|
this.disabledIcon = disabledIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getKey() {
|
public int getKey() {
|
||||||
@ -39,4 +49,14 @@ public enum DeviceType {
|
|||||||
}
|
}
|
||||||
return DeviceType.UNKNOWN;
|
return DeviceType.UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DrawableRes
|
||||||
|
public int getIcon() {
|
||||||
|
return defaultIcon;
|
||||||
|
}
|
||||||
|
|
||||||
|
@DrawableRes
|
||||||
|
public int getDisabledIcon() {
|
||||||
|
return disabledIcon;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -261,6 +261,35 @@ public class Weather {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String mapToOpenWeatherMapIcon(int openWeatherMapCondition) {
|
||||||
|
//see https://openweathermap.org/weather-conditions
|
||||||
|
String condition = "02d"; //generic "variable" icon
|
||||||
|
|
||||||
|
if (openWeatherMapCondition >= 200 && openWeatherMapCondition < 300) {
|
||||||
|
condition = "11d";
|
||||||
|
} else if (openWeatherMapCondition >= 300 && openWeatherMapCondition < 500) {
|
||||||
|
condition = "09d";
|
||||||
|
} else if (openWeatherMapCondition >= 500 && openWeatherMapCondition < 510) {
|
||||||
|
condition = "10d";
|
||||||
|
} else if (openWeatherMapCondition >= 511 && openWeatherMapCondition < 600) {
|
||||||
|
condition = "09d";
|
||||||
|
} else if (openWeatherMapCondition >= 600 && openWeatherMapCondition < 700) {
|
||||||
|
condition = "13d";
|
||||||
|
} else if (openWeatherMapCondition >= 700 && openWeatherMapCondition < 800) {
|
||||||
|
condition = "50d";
|
||||||
|
} else if (openWeatherMapCondition == 800) {
|
||||||
|
condition = "01d"; //TODO: night?
|
||||||
|
} else if (openWeatherMapCondition == 801) {
|
||||||
|
condition = "02d"; //TODO: night?
|
||||||
|
} else if (openWeatherMapCondition == 802) {
|
||||||
|
condition = "03d"; //TODO: night?
|
||||||
|
} else if (openWeatherMapCondition == 803 || openWeatherMapCondition == 804) {
|
||||||
|
condition = "04d"; //TODO: night?
|
||||||
|
}
|
||||||
|
|
||||||
|
return condition;
|
||||||
|
}
|
||||||
|
|
||||||
public static int mapToOpenWeatherMapCondition(int yahooCondition) {
|
public static int mapToOpenWeatherMapCondition(int yahooCondition) {
|
||||||
switch (yahooCondition) {
|
switch (yahooCondition) {
|
||||||
//yahoo weather conditions:
|
//yahoo weather conditions:
|
||||||
|
@ -25,6 +25,7 @@ public abstract class GBDeviceIoThread extends Thread {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user