1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-26 10:35:50 +01:00

Merge branch 'master' into background-javascript

This commit is contained in:
Andreas Shimokawa 2017-02-27 22:11:41 +01:00
commit 181b33d6be
9 changed files with 105 additions and 89 deletions

View File

@ -86,13 +86,13 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
for (int counter = 0; counter < 7; counter++) {
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));
day.add(Calendar.DATE, 1);
}
BarDataSet set = new BarDataSet(entries, "");
set.setColor(getMainColor());
set.setColors(getColors());
set.setValueFormatter(getFormatter());
BarData barData = new BarData(set);
@ -106,29 +106,32 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
}
private DayData refreshDayPie(DBHandler db, Calendar day, GBDevice device) {
ActivityAmounts amounts = getActivityAmountsForDay(db, day, device);
int totalValue = getTotalForActivityAmounts(amounts);
PieData data = new PieData();
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
colors.add(getMainColor());
if (totalValue < mTargetValue) {
entries.add(new PieEntry((mTargetValue - totalValue))); //we don't want labels on the pie chart
colors.add(Color.GRAY);
ActivityAmounts amounts = getActivityAmountsForDay(db, day, device);
float totalValues[] = getTotalsForActivityAmounts(amounts);
float totalValue = 0;
for (float value : totalValues) {
totalValue += value;
entries.add(new PieEntry(value));
}
PieDataSet set = new PieDataSet(entries, "");
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);
//this hides the values (numeric) added to the set. These would be shown aside the strings set with addXValue above
data.setDrawValues(false);
return new DayData(data, formatPieValue(totalValue));
return new DayData(data, formatPieValue((int) totalValue));
}
protected abstract String formatPieValue(int value);
@ -286,9 +289,9 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
abstract int getGoal();
abstract int getTotalForActivityAmounts(ActivityAmounts activityAmounts);
abstract float[] getTotalsForActivityAmounts(ActivityAmounts activityAmounts);
abstract IValueFormatter getFormatter();
abstract Integer getMainColor();
abstract int[] getColors();
}

View File

@ -24,14 +24,17 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
}
@Override
int getTotalForActivityAmounts(ActivityAmounts activityAmounts) {
long totalSeconds = 0;
float[] getTotalsForActivityAmounts(ActivityAmounts activityAmounts) {
long totalSecondsDeepSleep = 0;
long totalSecondsLightSleep = 0;
for (ActivityAmount amount : activityAmounts.getAmounts()) {
if ((amount.getActivityKind() & ActivityKind.TYPE_SLEEP) != 0) {
totalSeconds += amount.getTotalSeconds();
if (amount.getActivityKind() == ActivityKind.TYPE_DEEP_SLEEP) {
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
@ -50,7 +53,7 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
}
@Override
Integer getMainColor() {
return akLightSleep.color;
int[] getColors() {
return new int[]{akDeepSleep.color, akLightSleep.color};
}
}

View File

@ -24,13 +24,13 @@ public class WeekStepsChartFragment extends AbstractWeekChartFragment {
}
@Override
int getTotalForActivityAmounts(ActivityAmounts activityAmounts) {
float[] getTotalsForActivityAmounts(ActivityAmounts activityAmounts) {
int totalSteps = 0;
for (ActivityAmount amount : activityAmounts.getAmounts()) {
totalSteps += amount.getTotalSteps();
amount.getTotalSteps();
}
return totalSteps;
return new float[]{totalSteps};
}
@Override
@ -44,7 +44,7 @@ public class WeekStepsChartFragment extends AbstractWeekChartFragment {
}
@Override
Integer getMainColor() {
return akActivity.color;
int[] getColors() {
return new int[]{akActivity.color};
}
}

View File

@ -45,18 +45,7 @@ public class DeviceCandidateAdapter extends ArrayAdapter<GBDeviceCandidate> {
String name = formatDeviceCandidate(device);
deviceNameLabel.setText(name);
deviceAddressLabel.setText(device.getMacAddress());
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);
}
deviceImageView.setImageResource(device.getDeviceType().getIcon());
return view;
}

View File

@ -111,43 +111,10 @@ public class GBDeviceAdapter extends ArrayAdapter<GBDevice> {
batteryStatusLabel.setText("");
}
switch (device.getType()) {
case PEBBLE:
if (device.isConnected()) {
deviceImageView.setImageResource(R.drawable.ic_device_pebble);
} else {
deviceImageView.setImageResource(R.drawable.ic_device_pebble_disabled);
}
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);
}
if (device.isConnected()) {
deviceImageView.setImageResource(device.getType().getIcon());
} else {
deviceImageView.setImageResource(device.getType().getDisabledIcon());
}
return view;

View File

@ -6,7 +6,9 @@ import android.bluetooth.le.ScanFilter;
import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
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
* 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();
/**
* Returns the Activity class that will be used as the primary activity
* for the given device.
*
* @return
* @return the primary activity class, or null if none
*/
@Nullable
Class<? extends Activity> getPrimaryActivity();
/**

View File

@ -1,5 +1,9 @@
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.
*
@ -7,20 +11,26 @@ package nodomain.freeyourgadget.gadgetbridge.model;
* and may not be changed.
*/
public enum DeviceType {
UNKNOWN(-1),
PEBBLE(1),
MIBAND(10),
MIBAND2(11),
VIBRATISSIMO(20),
LIVEVIEW(30),
HPLUS(40),
MAKIBESF68(41),
TEST(1000);
UNKNOWN(-1, R.drawable.ic_launcher, R.drawable.ic_device_default_disabled),
PEBBLE(1, R.drawable.ic_device_pebble, R.drawable.ic_device_pebble_disabled),
MIBAND(10, R.drawable.ic_device_miband, R.drawable.ic_device_miband_disabled),
MIBAND2(11, R.drawable.ic_device_miband, R.drawable.ic_device_miband_disabled),
VIBRATISSIMO(20, R.drawable.ic_device_lovetoy, R.drawable.ic_device_lovetoy_disabled),
LIVEVIEW(30, R.drawable.ic_launcher, R.drawable.ic_device_default_disabled),
HPLUS(40, R.drawable.ic_device_hplus, R.drawable.ic_device_hplus_disabled),
MAKIBESF68(41, R.drawable.ic_device_hplus, R.drawable.ic_device_hplus_disabled),
TEST(1000, R.drawable.ic_launcher, R.drawable.ic_device_default_disabled);
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.defaultIcon = defaultIcon;
this.disabledIcon = disabledIcon;
}
public int getKey() {
@ -39,4 +49,14 @@ public enum DeviceType {
}
return DeviceType.UNKNOWN;
}
@DrawableRes
public int getIcon() {
return defaultIcon;
}
@DrawableRes
public int getDisabledIcon() {
return disabledIcon;
}
}

View File

@ -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) {
switch (yahooCondition) {
//yahoo weather conditions:

View File

@ -25,6 +25,7 @@ public abstract class GBDeviceIoThread extends Thread {
return false;
}
@Override
public void run() {
}