mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-29 05:16:51 +01:00
Finally, the prev and next buttons do something (#79)
Far from perfect, but a start.
This commit is contained in:
parent
964994972b
commit
bcf42f8022
@ -1,9 +1,17 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.activities.charts;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.github.mikephil.charting.charts.BarLineChartBase;
|
||||
import com.github.mikephil.charting.charts.Chart;
|
||||
@ -16,27 +24,35 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBAccess;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
||||
|
||||
public abstract class AbstractChartFragment extends Fragment {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ActivitySleepChartFragment.class);
|
||||
|
||||
public static final String ACTION_REFRESH
|
||||
= "nodomain.freeyourgadget.gadgetbridge.chart.action.refresh";
|
||||
|
||||
private final Set<String> mIntentFilterActions;
|
||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
AbstractChartFragment.this.onReceive(context, intent);
|
||||
}
|
||||
};
|
||||
|
||||
protected static final class ActivityConfig {
|
||||
public final int type;
|
||||
@ -50,6 +66,9 @@ public abstract class AbstractChartFragment extends Fragment {
|
||||
}
|
||||
}
|
||||
|
||||
private Date mStartDate;
|
||||
private Date mEndDate;
|
||||
|
||||
protected ActivityConfig akActivity = new ActivityConfig(ActivityKind.TYPE_ACTIVITY, "Activity", Color.rgb(89, 178, 44));
|
||||
protected ActivityConfig akLightSleep = new ActivityConfig(ActivityKind.TYPE_LIGHT_SLEEP, "Light Sleep", Color.rgb(182, 191, 255));
|
||||
protected ActivityConfig akDeepSleep = new ActivityConfig(ActivityKind.TYPE_DEEP_SLEEP, "Deep Sleep", Color.rgb(76, 90, 255));
|
||||
@ -59,6 +78,82 @@ public abstract class AbstractChartFragment extends Fragment {
|
||||
protected static final int CHART_TEXT_COLOR = Color.WHITE;
|
||||
protected static final int LEGEND_TEXT_COLOR = Color.WHITE;
|
||||
|
||||
protected AbstractChartFragment(String... intentFilterActions) {
|
||||
mIntentFilterActions = new HashSet<>();
|
||||
if (intentFilterActions != null) {
|
||||
mIntentFilterActions.addAll(Arrays.asList(intentFilterActions));
|
||||
mIntentFilterActions.add(ChartsHost.DATE_NEXT);
|
||||
mIntentFilterActions.add(ChartsHost.DATE_PREV);
|
||||
mIntentFilterActions.add(ChartsHost.REFRESH);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
initDates();
|
||||
|
||||
IntentFilter filter = new IntentFilter();
|
||||
for (String action : mIntentFilterActions) {
|
||||
filter.addAction(action);
|
||||
}
|
||||
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mReceiver, filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||
updateDateInfo(mStartDate, mEndDate);
|
||||
return view;
|
||||
}
|
||||
|
||||
public void setStartDate(Date date) {
|
||||
mStartDate = date;
|
||||
}
|
||||
|
||||
public void setEndDate(Date endDate) {
|
||||
mEndDate = endDate;
|
||||
}
|
||||
|
||||
protected void initDates() {
|
||||
setEndDate(new Date());
|
||||
setStartDate(DateTimeUtils.shiftByDays(mEndDate, -1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mReceiver);
|
||||
}
|
||||
|
||||
protected void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (ChartsHost.REFRESH.equals(action)) {
|
||||
refresh();
|
||||
} else if (ChartsHost.DATE_NEXT.equals(action)) {
|
||||
handleDateNext(mStartDate, mEndDate);
|
||||
} else if (ChartsHost.DATE_PREV.equals(action)) {
|
||||
handleDatePrev(mStartDate, mEndDate);
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleDatePrev(Date startDate, Date endDate) {
|
||||
shiftDates(startDate, endDate, -1);
|
||||
}
|
||||
|
||||
protected void handleDateNext(Date startDate, Date endDate) {
|
||||
shiftDates(startDate, endDate, +1);
|
||||
}
|
||||
|
||||
protected void shiftDates(Date startDate, Date endDate, int offset) {
|
||||
Date newStart = DateTimeUtils.shiftByDays(startDate, offset);
|
||||
Date newEnd = DateTimeUtils.shiftByDays(endDate, offset);
|
||||
|
||||
setDateRange(newStart, newEnd);
|
||||
refresh();
|
||||
}
|
||||
|
||||
protected Integer getColorFor(int activityKind) {
|
||||
switch (activityKind) {
|
||||
case ActivityKind.TYPE_DEEP_SLEEP:
|
||||
@ -369,4 +464,41 @@ public abstract class AbstractChartFragment extends Fragment {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setDateRange(Date from, Date to) {
|
||||
if (from.compareTo(to) > 0) {
|
||||
throw new IllegalArgumentException("Bad date range: " +from + ".." + to);
|
||||
}
|
||||
mStartDate = from;
|
||||
mEndDate = to;
|
||||
updateDateInfo(mStartDate, mEndDate);
|
||||
}
|
||||
|
||||
protected void updateDateInfo(Date from, Date to) {
|
||||
if (from.equals(to)) {
|
||||
getHost().setDateInfo(DateTimeUtils.formatDate(from));
|
||||
} else {
|
||||
getHost().setDateInfo(DateTimeUtils.formatDateRange(from, to));
|
||||
}
|
||||
}
|
||||
|
||||
protected List<ActivitySample> getSamples(DBHandler db, GBDevice device) {
|
||||
return getAllSamples(db, device, getTSStart(), getTSEnd());
|
||||
}
|
||||
|
||||
private int getTSEnd() {
|
||||
return toTimestamp(mEndDate);
|
||||
}
|
||||
|
||||
private int getTSStart() {
|
||||
return toTimestamp(mStartDate);
|
||||
}
|
||||
|
||||
private int toTimestamp(Date date) {
|
||||
return (int) ((date.getTime() / 1000) & 0xffffffff);
|
||||
}
|
||||
|
||||
protected ChartsHost getHost() {
|
||||
return (ChartsHost) getActivity();
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,8 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.activities.charts;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -22,10 +19,9 @@ import org.slf4j.LoggerFactory;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.ControlCenter;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
||||
|
||||
|
||||
@ -40,21 +36,6 @@ public class ActivitySleepChartFragment extends AbstractChartFragment {
|
||||
private int mSmartAlarmGoneOff = -1;
|
||||
private GBDevice mGBDevice = null;
|
||||
|
||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (action.equals(ACTION_REFRESH)) {
|
||||
// TODO: use LimitLines to visualize smart alarms?
|
||||
mSmartAlarmFrom = intent.getIntExtra("smartalarm_from", -1);
|
||||
mSmartAlarmTo = intent.getIntExtra("smartalarm_to", -1);
|
||||
mTimestampFrom = intent.getIntExtra("recording_base_timestamp", -1);
|
||||
mSmartAlarmGoneOff = intent.getIntExtra("alarm_gone_off", -1);
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
@ -65,11 +46,6 @@ public class ActivitySleepChartFragment extends AbstractChartFragment {
|
||||
mGBDevice = extras.getParcelable(GBDevice.EXTRA_DEVICE);
|
||||
}
|
||||
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(ControlCenter.ACTION_QUIT);
|
||||
filter.addAction(ACTION_REFRESH);
|
||||
|
||||
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mReceiver, filter);
|
||||
|
||||
mChart = (BarLineChartBase) rootView.findViewById(R.id.activitysleepchart);
|
||||
|
||||
@ -113,14 +89,23 @@ public class ActivitySleepChartFragment extends AbstractChartFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mReceiver);
|
||||
super.onDestroy();
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (action.equals(ChartsHost.REFRESH)) {
|
||||
// TODO: use LimitLines to visualize smart alarms?
|
||||
mSmartAlarmFrom = intent.getIntExtra("smartalarm_from", -1);
|
||||
mSmartAlarmTo = intent.getIntExtra("smartalarm_to", -1);
|
||||
mTimestampFrom = intent.getIntExtra("recording_base_timestamp", -1);
|
||||
mSmartAlarmGoneOff = intent.getIntExtra("alarm_gone_off", -1);
|
||||
refresh();
|
||||
} else {
|
||||
super.onReceive(context, intent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refreshInBackground(DBHandler db) {
|
||||
List<ActivitySample> samples = getSamples(db, mGBDevice, -1, -1);
|
||||
List<ActivitySample> samples = getSamples(db, mGBDevice);
|
||||
refresh(mGBDevice, mChart, samples);
|
||||
|
||||
mChart.getLegend().setTextColor(LEGEND_TEXT_COLOR);
|
||||
|
@ -15,19 +15,21 @@ import android.support.v4.view.ViewPager;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.ControlCenter;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.ControlCenter;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
|
||||
|
||||
public class ChartsActivity extends FragmentActivity {
|
||||
public class ChartsActivity extends FragmentActivity implements ChartsHost {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ChartsActivity.class);
|
||||
|
||||
@ -46,6 +48,11 @@ public class ChartsActivity extends FragmentActivity {
|
||||
*/
|
||||
private ViewPager mViewPager;
|
||||
|
||||
private ProgressBar mProgressBar;
|
||||
private Button mPrevButton;
|
||||
private Button mNextButton;
|
||||
private TextView mDateControl;
|
||||
|
||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
@ -63,7 +70,6 @@ public class ChartsActivity extends FragmentActivity {
|
||||
}
|
||||
}
|
||||
};
|
||||
private ProgressBar mProgressBar;
|
||||
|
||||
private void refreshBusyState(GBDevice dev) {
|
||||
if (dev.isBusy()) {
|
||||
@ -72,7 +78,7 @@ public class ChartsActivity extends FragmentActivity {
|
||||
boolean wasBusy = mProgressBar.getVisibility() != View.GONE;
|
||||
if (wasBusy) {
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(AbstractChartFragment.ACTION_REFRESH));
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(REFRESH));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -98,6 +104,30 @@ public class ChartsActivity extends FragmentActivity {
|
||||
mViewPager.setAdapter(mSectionsPagerAdapter);
|
||||
|
||||
mProgressBar = (ProgressBar) findViewById(R.id.charts_progress);
|
||||
mPrevButton = (Button) findViewById(R.id.charts_previous);
|
||||
mPrevButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
handlePrevButtonClicked();
|
||||
}
|
||||
});
|
||||
mNextButton = (Button) findViewById(R.id.charts_next);
|
||||
mNextButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
handleNextButtonClicked();
|
||||
}
|
||||
});
|
||||
|
||||
mDateControl = (TextView) findViewById(R.id.charts_text_date);
|
||||
}
|
||||
|
||||
private void handleNextButtonClicked() {
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(DATE_NEXT));
|
||||
}
|
||||
|
||||
private void handlePrevButtonClicked() {
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(DATE_PREV));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -128,6 +158,11 @@ public class ChartsActivity extends FragmentActivity {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDateInfo(String dateInfo) {
|
||||
mDateControl.setText(dateInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@link FragmentStatePagerAdapter} that returns a fragment corresponding to
|
||||
* one of the sections/tabs/pages.
|
||||
|
@ -0,0 +1,9 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.activities.charts;
|
||||
|
||||
public interface ChartsHost {
|
||||
public static final String DATE_PREV = ChartsActivity.class.getName().concat(".date_prev");
|
||||
public static final String DATE_NEXT = ChartsActivity.class.getName().concat(".date_next");
|
||||
public static final String REFRESH = ChartsActivity.class.getName().concat(".refresh");
|
||||
|
||||
void setDateInfo(String dateInfo);
|
||||
}
|
@ -1,11 +1,8 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.activities.charts;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -28,14 +25,13 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.ControlCenter;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityAmount;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityAmounts;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
||||
|
||||
|
||||
public class SleepChartFragment extends AbstractChartFragment {
|
||||
@ -50,21 +46,6 @@ public class SleepChartFragment extends AbstractChartFragment {
|
||||
private int mSmartAlarmGoneOff = -1;
|
||||
private GBDevice mGBDevice = null;
|
||||
|
||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (action.equals(ACTION_REFRESH)) {
|
||||
// TODO: use LimitLines to visualize smart alarms?
|
||||
mSmartAlarmFrom = intent.getIntExtra("smartalarm_from", -1);
|
||||
mSmartAlarmTo = intent.getIntExtra("smartalarm_to", -1);
|
||||
mTimestampFrom = intent.getIntExtra("recording_base_timestamp", -1);
|
||||
mSmartAlarmGoneOff = intent.getIntExtra("alarm_gone_off", -1);
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void refreshInBackground(DBHandler db) {
|
||||
List<ActivitySample> samples = getSamples(db);
|
||||
@ -73,13 +54,13 @@ public class SleepChartFragment extends AbstractChartFragment {
|
||||
}
|
||||
|
||||
private List<ActivitySample> getSamples(DBHandler db) {
|
||||
return getSamples(db, mGBDevice, -1, -1);
|
||||
return getSamples(db, mGBDevice);
|
||||
}
|
||||
|
||||
private void refreshSleepAmounts(GBDevice mGBDevice, PieChart pieChart, List<ActivitySample> samples) {
|
||||
ActivityAnalysis analysis = new ActivityAnalysis();
|
||||
ActivityAmounts amounts = analysis.calculateActivityAmounts(samples);
|
||||
String totalSleep = GB.formatDurationHoursMinutes(amounts.getTotalSeconds(), TimeUnit.SECONDS);
|
||||
String totalSleep = DateTimeUtils.formatDurationHoursMinutes(amounts.getTotalSeconds(), TimeUnit.SECONDS);
|
||||
pieChart.setCenterText(totalSleep);
|
||||
PieData data = new PieData();
|
||||
List<Entry> entries = new ArrayList<>();
|
||||
@ -95,7 +76,7 @@ public class SleepChartFragment extends AbstractChartFragment {
|
||||
set.setValueFormatter(new ValueFormatter() {
|
||||
@Override
|
||||
public String getFormattedValue(float value) {
|
||||
return GB.formatDurationHoursMinutes((long) value, TimeUnit.SECONDS);
|
||||
return DateTimeUtils.formatDurationHoursMinutes((long) value, TimeUnit.SECONDS);
|
||||
}
|
||||
});
|
||||
set.setColors(colors);
|
||||
@ -116,12 +97,6 @@ public class SleepChartFragment extends AbstractChartFragment {
|
||||
mGBDevice = extras.getParcelable(GBDevice.EXTRA_DEVICE);
|
||||
}
|
||||
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(ControlCenter.ACTION_QUIT);
|
||||
filter.addAction(ACTION_REFRESH);
|
||||
|
||||
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mReceiver, filter);
|
||||
|
||||
mActivityChart = (BarLineChartBase) rootView.findViewById(R.id.sleepchart);
|
||||
mSleepAmountChart = (PieChart) rootView.findViewById(R.id.sleepchart_pie_light_deep);
|
||||
|
||||
@ -133,6 +108,21 @@ public class SleepChartFragment extends AbstractChartFragment {
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (action.equals(ChartsHost.REFRESH)) {
|
||||
// TODO: use LimitLines to visualize smart alarms?
|
||||
mSmartAlarmFrom = intent.getIntExtra("smartalarm_from", -1);
|
||||
mSmartAlarmTo = intent.getIntExtra("smartalarm_to", -1);
|
||||
mTimestampFrom = intent.getIntExtra("recording_base_timestamp", -1);
|
||||
mSmartAlarmGoneOff = intent.getIntExtra("alarm_gone_off", -1);
|
||||
refresh();
|
||||
} else {
|
||||
super.onReceive(context, intent);
|
||||
}
|
||||
}
|
||||
|
||||
private void setupSleepAmountChart() {
|
||||
mSleepAmountChart.setBackgroundColor(BACKGROUND_COLOR);
|
||||
mSleepAmountChart.setDescriptionColor(DESCRIPTION_COLOR);
|
||||
@ -141,13 +131,6 @@ public class SleepChartFragment extends AbstractChartFragment {
|
||||
mSleepAmountChart.setNoDataText("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mReceiver);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
||||
private void setupActivityChart() {
|
||||
mActivityChart.setBackgroundColor(BACKGROUND_COLOR);
|
||||
mActivityChart.setDescriptionColor(DESCRIPTION_COLOR);
|
||||
|
@ -1,12 +1,7 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.activities.charts;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -33,11 +28,10 @@ import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.ControlCenter;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandCoordinator;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
||||
|
||||
|
||||
@ -52,16 +46,6 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
||||
|
||||
private GBDevice mGBDevice = null;
|
||||
|
||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (action.equals(ACTION_REFRESH)) {
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void refreshInBackground(DBHandler db) {
|
||||
Calendar day = Calendar.getInstance();
|
||||
@ -153,12 +137,6 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
||||
mTargetSteps = MiBandCoordinator.getFitnessGoal(mGBDevice.getAddress());
|
||||
}
|
||||
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(ControlCenter.ACTION_QUIT);
|
||||
filter.addAction(ACTION_REFRESH);
|
||||
|
||||
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mReceiver, filter);
|
||||
|
||||
mWeekStepsChart = (BarLineChartBase) rootView.findViewById(R.id.sleepchart);
|
||||
mTodayStepsChart = (PieChart) rootView.findViewById(R.id.sleepchart_pie_light_deep);
|
||||
|
||||
@ -178,13 +156,6 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
||||
mTodayStepsChart.setNoDataText("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mReceiver);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
||||
private void setupWeekStepsChart() {
|
||||
mWeekStepsChart.setBackgroundColor(BACKGROUND_COLOR);
|
||||
mWeekStepsChart.setDescriptionColor(DESCRIPTION_COLOR);
|
||||
|
@ -19,6 +19,7 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.AppManagerActivity;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsHost;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.receivers.GBCallControlReceiver;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
@ -163,7 +164,7 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
|
||||
public void handleGBDeviceEvent(GBDeviceEventSleepMonitorResult sleepMonitorResult) {
|
||||
Context context = getContext();
|
||||
LOG.info("Got event for SLEEP_MONIOR_RES");
|
||||
Intent sleepMontiorIntent = new Intent(AbstractChartFragment.ACTION_REFRESH);
|
||||
Intent sleepMontiorIntent = new Intent(ChartsHost.REFRESH);
|
||||
sleepMontiorIntent.putExtra("smartalarm_from", sleepMonitorResult.smartalarm_from);
|
||||
sleepMontiorIntent.putExtra("smartalarm_to", sleepMonitorResult.smartalarm_to);
|
||||
sleepMontiorIntent.putExtra("recording_base_timestamp", sleepMonitorResult.recording_base_timestamp);
|
||||
|
@ -12,7 +12,6 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -41,6 +40,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.AbortTransactio
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceBusyAction;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetProgressAction;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.DEFAULT_VALUE_FLASH_COLOUR;
|
||||
@ -831,7 +831,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
if (firstChunk && dataUntilNextHeader != 0) {
|
||||
GB.toast(getContext().getString(R.string.user_feedback_miband_activity_data_transfer,
|
||||
GB.formatDurationHoursMinutes((totalDataToRead / 3), TimeUnit.MINUTES),
|
||||
DateTimeUtils.formatDurationHoursMinutes((totalDataToRead / 3), TimeUnit.MINUTES),
|
||||
DateFormat.getDateTimeInstance().format(timestamp.getTime())), Toast.LENGTH_LONG, GB.INFO);
|
||||
}
|
||||
LOG.info("total data to read: " + totalDataToRead + " len: " + (totalDataToRead / 3) + " minute(s)");
|
||||
|
@ -0,0 +1,48 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.util;
|
||||
|
||||
import android.text.format.DateUtils;
|
||||
|
||||
import com.github.pfichtner.durationformatter.DurationFormatter;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
|
||||
public class DateTimeUtils {
|
||||
public static String formatDate(Date date) {
|
||||
return DateUtils.formatDateTime(GBApplication.getContext(), date.getTime(), DateUtils.FORMAT_SHOW_DATE);
|
||||
// long dateMillis = date.getTime();
|
||||
// if (isToday(dateMillis)) {
|
||||
// return "Today";
|
||||
// }
|
||||
// if (isYesterday(dateMillis)) {
|
||||
// return "Yesterday";
|
||||
// }
|
||||
// DateFormat.getDateInstance(DateFormat.SHORT).format(date);
|
||||
}
|
||||
|
||||
public static String formatDurationHoursMinutes(long duration, TimeUnit unit) {
|
||||
DurationFormatter df = DurationFormatter.Builder.SYMBOLS
|
||||
.maximum(TimeUnit.DAYS)
|
||||
.minimum(TimeUnit.MINUTES)
|
||||
.suppressZeros(DurationFormatter.SuppressZeros.LEADING)
|
||||
.maximumAmountOfUnitsToShow(2)
|
||||
.build();
|
||||
return df.format(duration, unit);
|
||||
}
|
||||
|
||||
public static String formatDateRange(Date from, Date to) {
|
||||
return DateUtils.formatDateRange(GBApplication.getContext(), from.getTime(), to.getTime(), DateUtils.FORMAT_SHOW_DATE);
|
||||
}
|
||||
|
||||
public static Date shiftByDays(Date date, int offset) {
|
||||
Calendar cal = GregorianCalendar.getInstance();
|
||||
cal.setTime(date);
|
||||
cal.add(GregorianCalendar.DAY_OF_YEAR, offset);
|
||||
Date newDate = cal.getTime();
|
||||
return newDate;
|
||||
}
|
||||
}
|
@ -24,6 +24,10 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
@ -262,16 +266,6 @@ public class GB {
|
||||
}
|
||||
}
|
||||
|
||||
public static String formatDurationHoursMinutes(long duration, TimeUnit unit) {
|
||||
DurationFormatter df = DurationFormatter.Builder.SYMBOLS
|
||||
.maximum(TimeUnit.DAYS)
|
||||
.minimum(TimeUnit.MINUTES)
|
||||
.suppressZeros(DurationFormatter.SuppressZeros.LEADING)
|
||||
.maximumAmountOfUnitsToShow(2)
|
||||
.build();
|
||||
return df.format(duration, unit);
|
||||
}
|
||||
|
||||
private static Notification createInstallNotification(String text, boolean ongoing,
|
||||
int percentage, Context context) {
|
||||
Intent notificationIntent = new Intent(context, ControlCenter.class);
|
||||
@ -304,5 +298,4 @@ public class GB {
|
||||
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
nm.notify(NOTIFICATION_ID_INSTALL, notification);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,11 +17,13 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="<" />
|
||||
<Button
|
||||
android:id="@+id/charts_next"
|
||||
<TextView
|
||||
android:id="@+id/charts_text_date"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text=">" />
|
||||
android:layout_weight="5"
|
||||
android:text="Today"
|
||||
/>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/charts_progress"
|
||||
@ -30,6 +32,13 @@
|
||||
android:indeterminate="true"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/charts_next"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text=">" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<android.support.v4.view.ViewPager android:id="@+id/pager"
|
||||
|
Loading…
Reference in New Issue
Block a user