1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 21:06:50 +01:00

Merge branch 'master' into bip-wip

This commit is contained in:
Daniele Gobbetti 2017-11-01 22:12:13 +01:00
commit 331ca6a47e
14 changed files with 141 additions and 99 deletions

View File

@ -1,5 +1,9 @@
### Changelog
#### Version NEXT
* Charts: added preference to disable swiping charts left/right and some UI changes
* Pebble: Use the configured unit system also for system weather app
#### Version 0.22.1
* Mi Band 2: Fix being detected as Amazfit Bip which lead to various problems especially on newly paired devices

View File

@ -1,4 +1,4 @@
GNU AFFERO GENERAL PUBLIC LICENSE
GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
@ -659,4 +659,3 @@ specific requirements.
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU AGPL, see
<http://www.gnu.org/licenses/>.

View File

@ -35,16 +35,12 @@ import com.github.mikephil.charting.charts.BarLineChartBase;
import com.github.mikephil.charting.charts.Chart;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.ChartData;
import com.github.mikephil.charting.data.CombinedData;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -419,7 +415,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
*/
protected abstract void renderCharts();
protected DefaultChartsData<CombinedData> refresh(GBDevice gbDevice, List<? extends ActivitySample> samples) {
protected DefaultChartsData<LineData> refresh(GBDevice gbDevice, List<? extends ActivitySample> samples) {
// Calendar cal = GregorianCalendar.getInstance();
// cal.clear();
TimestampTranslation tsTranslation = new TimestampTranslation();
@ -429,7 +425,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
// ArrayList<String> xLabels = null;
LOG.info("" + getTitle() + ": number of samples:" + samples.size());
CombinedData combinedData;
LineData lineData;
if (samples.size() > 1) {
boolean annotate = true;
boolean use_steps_as_movement;
@ -437,7 +433,10 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
int last_type = ActivityKind.TYPE_UNKNOWN;
int numEntries = samples.size();
List<BarEntry> activityEntries = new ArrayList<>(numEntries);
List<Entry> activityEntries = new ArrayList<>(numEntries);
List<Entry> deepSleepEntries = new ArrayList<>(numEntries);
List<Entry> lightSleepEntries = new ArrayList<>(numEntries);
List<Entry> notWornEntries = new ArrayList<>(numEntries);
boolean hr = supportsHeartrate(gbDevice);
List<Entry> heartrateEntries = hr ? new ArrayList<Entry>(numEntries) : null;
List<Integer> colors = new ArrayList<>(numEntries); // this is kinda inefficient...
@ -466,15 +465,34 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
float value = movement;
switch (type) {
case ActivityKind.TYPE_DEEP_SLEEP:
value += SleepUtils.Y_VALUE_DEEP_SLEEP;
colors.add(akDeepSleep.color);
if (last_type != type) { //FIXME: this is ugly but it works (repeated in each case)
deepSleepEntries.add(createLineEntry(0, ts - 1));
lightSleepEntries.add(createLineEntry(0, ts));
notWornEntries.add(createLineEntry(0, ts));
activityEntries.add(createLineEntry(0, ts));
}
deepSleepEntries.add(createLineEntry(value + SleepUtils.Y_VALUE_DEEP_SLEEP, ts));
break;
case ActivityKind.TYPE_LIGHT_SLEEP:
colors.add(akLightSleep.color);
if (last_type != type) {
lightSleepEntries.add(createLineEntry(0, ts - 1));
deepSleepEntries.add(createLineEntry(0, ts));
notWornEntries.add(createLineEntry(0, ts));
activityEntries.add(createLineEntry(0, ts));
}
lightSleepEntries.add(createLineEntry(value, ts));
break;
case ActivityKind.TYPE_NOT_WORN:
value = SleepUtils.Y_VALUE_DEEP_SLEEP; //a small value, just to show something on the graphs
colors.add(akNotWorn.color);
if (last_type != type) {
notWornEntries.add(createLineEntry(0, ts - 1));
lightSleepEntries.add(createLineEntry(0, ts));
deepSleepEntries.add(createLineEntry(0, ts));
activityEntries.add(createLineEntry(0, ts));
}
notWornEntries.add(createLineEntry(SleepUtils.Y_VALUE_DEEP_SLEEP, ts)); //a small value, just to show something on the graphs
break;
default:
// short steps = sample.getSteps();
@ -483,9 +501,15 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
// movement = steps;
// }
// value = ((float) movement) / movement_divisor;
colors.add(akActivity.color);
if (last_type != type) {
activityEntries.add(createLineEntry(0, ts - 1));
lightSleepEntries.add(createLineEntry(0, ts));
notWornEntries.add(createLineEntry(0, ts));
deepSleepEntries.add(createLineEntry(0, ts));
}
activityEntries.add(createLineEntry(value, ts));
}
activityEntries.add(createBarEntry(value, ts));
if (hr && HeartRateUtils.isValidHeartRateValue(sample.getHeartRate())) {
if (lastHrSampleIndex > -1 && ts - lastHrSampleIndex > 1800*HeartRateUtils.MAX_HR_MEASUREMENTS_GAP_MINUTES) {
heartrateEntries.add(createLineEntry(0, lastHrSampleIndex + 1));
@ -519,35 +543,36 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
// chart.getXAxis().addLimitLine(line);
// }
// }
// last_type = type;
}
last_type = type;
}
BarDataSet activitySet = createActivitySet(activityEntries, colors, "Activity");
// create a data object with the datasets
// combinedData = new CombinedData(xLabels);
combinedData = new CombinedData();
List<IBarDataSet> list = new ArrayList<>();
list.add(activitySet);
BarData barData = new BarData(list);
barData.setBarWidth(200f);
// barData.setGroupSpace(0);
combinedData.setData(barData);
List<ILineDataSet> lineDataSets = new ArrayList<>();
LineDataSet activitySet = createDataSet(activityEntries, akActivity.color, "Activity");
lineDataSets.add(activitySet);
LineDataSet deepSleepSet = createDataSet(deepSleepEntries, akDeepSleep.color, "Deep Sleep");
lineDataSets.add(deepSleepSet);
LineDataSet lightSleepSet = createDataSet(lightSleepEntries, akLightSleep.color, "Light Sleep");
lineDataSets.add(lightSleepSet);
LineDataSet notWornSet = createDataSet(notWornEntries, akNotWorn.color, "Not worn");
lineDataSets.add(notWornSet);
if (hr && heartrateEntries.size() > 0) {
LineDataSet heartrateSet = createHeartrateSet(heartrateEntries, "Heart Rate");
LineData lineData = new LineData(heartrateSet);
combinedData.setData(lineData);
lineDataSets.add(heartrateSet);
}
lineData = new LineData(lineDataSets);
// chart.setDescription(getString(R.string.sleep_activity_date_range, dateStringFrom, dateStringTo));
// chart.setDescriptionPosition(?, ?);
} else {
combinedData = new CombinedData();
lineData = new LineData();
}
IAxisValueFormatter xValueFormatter = new SampleXLabelFormatter(tsTranslation);
return new DefaultChartsData(combinedData, xValueFormatter);
return new DefaultChartsData(lineData, xValueFormatter);
}
/**
@ -563,24 +588,21 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
protected abstract void setupLegend(Chart chart);
protected BarEntry createBarEntry(float value, int xValue) {
return new BarEntry(xValue, value);
}
protected Entry createLineEntry(float value, int xValue) {
return new Entry(xValue, value);
}
protected BarDataSet createActivitySet(List<BarEntry> values, List<Integer> colors, String label) {
BarDataSet set1 = new BarDataSet(values, label);
set1.setColors(colors);
protected LineDataSet createDataSet(List<Entry> values, Integer color, String label) {
LineDataSet set1 = new LineDataSet(values, label);
set1.setColor(color);
// set1.setDrawCubic(true);
// set1.setCubicIntensity(0.2f);
// //set1.setDrawFilled(true);
// set1.setDrawCircles(false);
set1.setDrawFilled(true);
set1.setDrawCircles(false);
// set1.setLineWidth(2f);
// set1.setCircleSize(5f);
// set1.setFillColor(ColorTemplate.getHoloBlue());
set1.setFillColor(color);
set1.setFillAlpha(255);
set1.setDrawValues(false);
// set1.setHighLightColor(Color.rgb(128, 0, 255));
// set1.setColor(Color.rgb(89, 178, 44));
@ -610,40 +632,6 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
return set1;
}
protected BarDataSet createDeepSleepSet(List<BarEntry> values, String label) {
BarDataSet set1 = new BarDataSet(values, label);
// set1.setDrawCubic(true);
// set1.setCubicIntensity(0.2f);
// //set1.setDrawFilled(true);
// set1.setDrawCircles(false);
// set1.setLineWidth(2f);
// set1.setCircleSize(5f);
// set1.setFillColor(ColorTemplate.getHoloBlue());
set1.setDrawValues(false);
// set1.setHighLightColor(Color.rgb(244, 117, 117));
// set1.setColor(Color.rgb(76, 90, 255));
set1.setValueTextColor(CHART_TEXT_COLOR);
return set1;
}
protected BarDataSet createLightSleepSet(List<BarEntry> values, String label) {
BarDataSet set1 = new BarDataSet(values, label);
// set1.setDrawCubic(true);
// set1.setCubicIntensity(0.2f);
// //set1.setDrawFilled(true);
// set1.setDrawCircles(false);
// set1.setLineWidth(2f);
// set1.setCircleSize(5f);
// set1.setFillColor(ColorTemplate.getHoloBlue());
set1.setDrawValues(false);
// set1.setHighLightColor(Color.rgb(244, 117, 117));
// set1.setColor(Color.rgb(182, 191, 255));
set1.setValueTextColor(CHART_TEXT_COLOR);
// set1.setColor(Color.CYAN);
return set1;
}
protected RefreshTask createRefreshTask(String task, Context context) {
return new RefreshTask(task, context);
}

View File

@ -25,11 +25,12 @@ import android.view.View;
import android.view.ViewGroup;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.BarLineChartBase;
import com.github.mikephil.charting.charts.Chart;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.LegendEntry;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.LineData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -47,7 +48,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
public class ActivitySleepChartFragment extends AbstractChartFragment {
protected static final Logger LOG = LoggerFactory.getLogger(ActivitySleepChartFragment.class);
private BarLineChartBase mChart;
private LineChart mChart;
private int mSmartAlarmFrom = -1;
private int mSmartAlarmTo = -1;
@ -59,7 +60,7 @@ public class ActivitySleepChartFragment extends AbstractChartFragment {
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_charts, container, false);
mChart = (BarLineChartBase) rootView.findViewById(R.id.activitysleepchart);
mChart = (LineChart) rootView.findViewById(R.id.activitysleepchart);
setupChart();
@ -136,7 +137,7 @@ public class ActivitySleepChartFragment extends AbstractChartFragment {
mChart.getLegend().setTextColor(LEGEND_TEXT_COLOR);
mChart.setData(null); // workaround for https://github.com/PhilJay/MPAndroidChart/issues/2317
mChart.getXAxis().setValueFormatter(dcd.getXValueFormatter());
mChart.setData(dcd.getData());
mChart.setData((LineData) dcd.getData());
}
@Override

View File

@ -29,8 +29,10 @@ import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.AttributeSet;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
@ -66,7 +68,7 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
private Date mStartDate;
private Date mEndDate;
private SwipeRefreshLayout swipeLayout;
private ViewPager viewPager;
private NonSwipeableViewPager viewPager;
LimitedQueue mActivityAmountCache = new LimitedQueue(60);
@ -153,7 +155,7 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
enableSwipeRefresh(true);
// Set up the ViewPager with the sections adapter.
viewPager = (ViewPager) findViewById(R.id.charts_pager);
viewPager = (NonSwipeableViewPager) findViewById(R.id.charts_pager);
viewPager.setAdapter(getPagerAdapter());
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
@ -365,3 +367,26 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
}
}
}
class NonSwipeableViewPager extends ViewPager {
public NonSwipeableViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (GBApplication.getPrefs().getBoolean("charts_allow_swipe", true)) {
return super.onInterceptTouchEvent(ev);
}
return false;
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (GBApplication.getPrefs().getBoolean("charts_allow_swipe", true)) {
return super.onTouchEvent(ev);
}
return false;
}
}

View File

@ -26,13 +26,13 @@ import android.view.ViewGroup;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.Chart;
import com.github.mikephil.charting.charts.CombinedChart;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.LegendEntry;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.CombinedData;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;
@ -60,7 +60,7 @@ import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
public class SleepChartFragment extends AbstractChartFragment {
protected static final Logger LOG = LoggerFactory.getLogger(ActivitySleepChartFragment.class);
private CombinedChart mActivityChart;
private LineChart mActivityChart;
private PieChart mSleepAmountChart;
private int mSmartAlarmFrom = -1;
@ -136,7 +136,7 @@ public class SleepChartFragment extends AbstractChartFragment {
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_sleepchart, container, false);
mActivityChart = (CombinedChart) rootView.findViewById(R.id.sleepchart);
mActivityChart = (LineChart) rootView.findViewById(R.id.sleepchart);
mSleepAmountChart = (PieChart) rootView.findViewById(R.id.sleepchart_pie_light_deep);
setupActivityChart();
@ -262,10 +262,10 @@ public class SleepChartFragment extends AbstractChartFragment {
}
private static class MyChartsData extends ChartsData {
private final DefaultChartsData<CombinedData> chartsData;
private final DefaultChartsData<LineData> chartsData;
private final MySleepChartsData pieData;
public MyChartsData(MySleepChartsData pieData, DefaultChartsData<CombinedData> chartsData) {
public MyChartsData(MySleepChartsData pieData, DefaultChartsData<LineData> chartsData) {
this.pieData = pieData;
this.chartsData = chartsData;
}
@ -274,7 +274,7 @@ public class SleepChartFragment extends AbstractChartFragment {
return pieData;
}
public DefaultChartsData<CombinedData> getChartsData() {
public DefaultChartsData<LineData> getChartsData() {
return chartsData;
}
}

View File

@ -39,6 +39,7 @@ import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppInfo;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppManagement;
@ -1222,6 +1223,20 @@ public class PebbleProtocol extends GBDeviceProtocol {
}
private byte[] encodeWeatherForecast(WeatherSpec weatherSpec) {
short currentTemp = (short) (weatherSpec.currentTemp - 273);
short todayMax = (short) (weatherSpec.todayMaxTemp - 273);
short todayMin = (short) (weatherSpec.todayMinTemp - 273);
short tomorrowMax = (short) (weatherSpec.tomorrowMaxTemp - 273);
short tomorrowMin = (short) (weatherSpec.tomorrowMinTemp - 273);
String units = GBApplication.getPrefs().getString(SettingsActivity.PREF_MEASUREMENT_SYSTEM, GBApplication.getContext().getString(R.string.p_unit_metric));
if (units.equals(GBApplication.getContext().getString(R.string.p_unit_imperial))) {
currentTemp = (short) (currentTemp * 1.8f + 32);
todayMax = (short) (todayMax * 1.8f + 32);
todayMin = (short) (todayMin * 1.8f + 32);
tomorrowMax = (short) (tomorrowMax * 1.8f + 32);
tomorrowMin = (short) (tomorrowMin * 1.8f + 32);
}
final short WEATHER_FORECAST_LENGTH = 20;
String[] parts = {weatherSpec.location, weatherSpec.currentCondition};
@ -1242,13 +1257,13 @@ public class PebbleProtocol extends GBDeviceProtocol {
ByteBuffer buf = ByteBuffer.allocate(pin_length);
buf.order(ByteOrder.LITTLE_ENDIAN);
buf.put((byte) 3); // unknown, always 3?
buf.putShort((short) (weatherSpec.currentTemp - 273));
buf.putShort(currentTemp);
buf.put(Weather.mapToPebbleCondition(weatherSpec.currentConditionCode));
buf.putShort((short) (weatherSpec.todayMaxTemp - 273));
buf.putShort((short) (weatherSpec.todayMinTemp - 273));
buf.putShort(todayMax);
buf.putShort(todayMin);
buf.put(Weather.mapToPebbleCondition(weatherSpec.tomorrowConditionCode));
buf.putShort((short) (weatherSpec.tomorrowMaxTemp - 273));
buf.putShort((short) (weatherSpec.tomorrowMinTemp - 273));
buf.putShort(tomorrowMax);
buf.putShort(tomorrowMin);
buf.putInt(weatherSpec.timestamp);
buf.put((byte) 0); // automatic location 0=manual 1=auto
buf.putShort(attributes_length);

View File

@ -11,7 +11,7 @@
android:layout_weight="40">
</com.github.mikephil.charting.charts.PieChart>
<com.github.mikephil.charting.charts.CombinedChart
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/sleepchart"
android:layout_width="fill_parent"
android:layout_height="fill_parent"

View File

@ -12,7 +12,7 @@
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.view.ViewPager
<nodomain.freeyourgadget.gadgetbridge.activities.charts.NonSwipeableViewPager
android:id="@+id/charts_pager"
android:layout_width="match_parent"
android:layout_height="0dp"
@ -25,7 +25,7 @@
android:layout_height="wrap_content"
android:layout_gravity="top"
app:tabMode="scrollable" />
</android.support.v4.view.ViewPager>
</nodomain.freeyourgadget.gadgetbridge.activities.charts.NonSwipeableViewPager>
<LinearLayout
android:id="@+id/charts_date_bar"

View File

@ -4,7 +4,7 @@
android:layout_height="match_parent"
tools:context="nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity$PlaceholderFragment">
<com.github.mikephil.charting.charts.CombinedChart
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/activitysleepchart"
android:layout_width="match_parent"
android:layout_height="match_parent"

View File

@ -11,7 +11,7 @@
android:layout_height="fill_parent"
android:layout_weight="20"></com.github.mikephil.charting.charts.PieChart>
<com.github.mikephil.charting.charts.CombinedChart
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/sleepchart"
android:layout_width="fill_parent"
android:layout_height="fill_parent"

View File

@ -70,6 +70,7 @@
<string name="pref_title_general_autocreonnect">Reconnect automatically</string>
<string name="pref_title_audo_player">Preferred Audioplayer</string>
<string name="pref_default">Default</string>
<string name="pref_title_charts_swipe">Enable left/right swipe in the charts activity</string>
<string name="pref_header_datetime">Date and Time</string>
<string name="pref_title_datetime_syctimeonconnect">Sync time</string>

View File

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<changelog>
<release version="next">
<change>Charts: added preference to disable swiping charts left/right and some UI changes
</change>
<change>Pebble: Use the configured unit system also for system weather app</change>
</release>
<release version="0.22.1" versioncode="109">
<change>Mi Band 2: Fix being detected as Amazfit Bip which lead to various problems especially on newly paired devices</change>
</release>

View File

@ -92,6 +92,10 @@
android:maxLength="2"
android:title="@string/activity_prefs_sleep_duration" />
</PreferenceScreen>
<CheckBoxPreference
android:defaultValue="true"
android:key="charts_allow_swipe"
android:title="@string/pref_title_charts_swipe" />
</PreferenceCategory>
<PreferenceCategory
android:key="pref_key_datetime"