Merge pull request #768 from AdrianLxM/chart-menu2
Chart menu - also for history-browser
This commit is contained in:
commit
2cd1d2014d
|
@ -2,10 +2,16 @@ package info.nightscout.androidaps;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.content.res.ResourcesCompat;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
import android.support.v7.widget.PopupMenu;
|
||||||
|
import android.text.SpannableString;
|
||||||
|
import android.text.style.ForegroundColorSpan;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.CheckBox;
|
import android.widget.ImageButton;
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
|
|
||||||
import com.jjoe64.graphview.GraphView;
|
import com.jjoe64.graphview.GraphView;
|
||||||
|
@ -26,6 +32,7 @@ import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.OverviewFragment;
|
||||||
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
|
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Overview.graphData.GraphData;
|
import info.nightscout.androidaps.plugins.Overview.graphData.GraphData;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
|
@ -34,6 +41,13 @@ import info.nightscout.utils.SP;
|
||||||
public class HistoryBrowseActivity extends AppCompatActivity {
|
public class HistoryBrowseActivity extends AppCompatActivity {
|
||||||
private static Logger log = LoggerFactory.getLogger(HistoryBrowseActivity.class);
|
private static Logger log = LoggerFactory.getLogger(HistoryBrowseActivity.class);
|
||||||
|
|
||||||
|
|
||||||
|
ImageButton chartButton;
|
||||||
|
|
||||||
|
boolean showBasal = true;
|
||||||
|
boolean showIob, showCob, showDev, showRat;
|
||||||
|
|
||||||
|
|
||||||
@BindView(R.id.historybrowse_date)
|
@BindView(R.id.historybrowse_date)
|
||||||
Button buttonDate;
|
Button buttonDate;
|
||||||
@BindView(R.id.historybrowse_zoom)
|
@BindView(R.id.historybrowse_zoom)
|
||||||
|
@ -45,19 +59,6 @@ public class HistoryBrowseActivity extends AppCompatActivity {
|
||||||
@BindView(R.id.historybrowse_seekBar)
|
@BindView(R.id.historybrowse_seekBar)
|
||||||
SeekBar seekBar;
|
SeekBar seekBar;
|
||||||
|
|
||||||
@BindView(R.id.overview_showprediction)
|
|
||||||
CheckBox showPredictionCheckbox;
|
|
||||||
@BindView(R.id.overview_showbasals)
|
|
||||||
CheckBox showBasalsCheckbox;
|
|
||||||
@BindView(R.id.overview_showiob)
|
|
||||||
CheckBox showIobCheckbox;
|
|
||||||
@BindView(R.id.overview_showcob)
|
|
||||||
CheckBox showCobCheckbox;
|
|
||||||
@BindView(R.id.overview_showdeviations)
|
|
||||||
CheckBox showDeviationsCheckbox;
|
|
||||||
@BindView(R.id.overview_showratios)
|
|
||||||
CheckBox showRatiosCheckbox;
|
|
||||||
|
|
||||||
private int rangeToDisplay = 24; // for graph
|
private int rangeToDisplay = 24; // for graph
|
||||||
private long start;
|
private long start;
|
||||||
|
|
||||||
|
@ -85,6 +86,8 @@ public class HistoryBrowseActivity extends AppCompatActivity {
|
||||||
iobGraph.getGridLabelRenderer().setLabelVerticalWidth(50);
|
iobGraph.getGridLabelRenderer().setLabelVerticalWidth(50);
|
||||||
iobGraph.getGridLabelRenderer().setNumVerticalLabels(5);
|
iobGraph.getGridLabelRenderer().setNumVerticalLabels(5);
|
||||||
|
|
||||||
|
setupChartMenu();
|
||||||
|
|
||||||
// set start of current day
|
// set start of current day
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
calendar.setTimeInMillis(System.currentTimeMillis());
|
calendar.setTimeInMillis(System.currentTimeMillis());
|
||||||
|
@ -162,15 +165,6 @@ public class HistoryBrowseActivity extends AppCompatActivity {
|
||||||
void onClickDate() {
|
void onClickDate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick({R.id.overview_showbasals, R.id.overview_showprediction, R.id.overview_showiob, R.id.overview_showcob, R.id.overview_showdeviations, R.id.overview_showratios})
|
|
||||||
void onClickDate(View view) {
|
|
||||||
//((CheckBox) view).toggle();
|
|
||||||
updateGUI("checkboxToggle");
|
|
||||||
iobCobCalculatorPlugin.clearCache();
|
|
||||||
iobCobCalculatorPlugin.runCalculation("onClickDate", start, true, eventCustomCalculationFinished);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventAutosensCalculationFinished e) {
|
public void onStatusEvent(final EventAutosensCalculationFinished e) {
|
||||||
Activity activity = this;
|
Activity activity = this;
|
||||||
|
@ -247,7 +241,7 @@ public class HistoryBrowseActivity extends AppCompatActivity {
|
||||||
graphData.addTreatments(fromTime, toTime);
|
graphData.addTreatments(fromTime, toTime);
|
||||||
|
|
||||||
// add basal data
|
// add basal data
|
||||||
if (pump.getPumpDescription().isTempBasalCapable && showBasalsCheckbox.isChecked()) {
|
if (pump.getPumpDescription().isTempBasalCapable && showBasal) {
|
||||||
graphData.addBasals(fromTime, toTime, lowLine / graphData.maxY / 1.2d);
|
graphData.addBasals(fromTime, toTime, lowLine / graphData.maxY / 1.2d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,23 +257,23 @@ public class HistoryBrowseActivity extends AppCompatActivity {
|
||||||
boolean useDevForScale = false;
|
boolean useDevForScale = false;
|
||||||
boolean useRatioForScale = false;
|
boolean useRatioForScale = false;
|
||||||
|
|
||||||
if (showIobCheckbox.isChecked()) {
|
if (showIob) {
|
||||||
useIobForScale = true;
|
useIobForScale = true;
|
||||||
} else if (showCobCheckbox.isChecked()) {
|
} else if (showCob) {
|
||||||
useCobForScale = true;
|
useCobForScale = true;
|
||||||
} else if (showDeviationsCheckbox.isChecked()) {
|
} else if (showDev) {
|
||||||
useDevForScale = true;
|
useDevForScale = true;
|
||||||
} else if (showRatiosCheckbox.isChecked()) {
|
} else if (showRat) {
|
||||||
useRatioForScale = true;
|
useRatioForScale = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showIobCheckbox.isChecked())
|
if (showIob)
|
||||||
secondGraphData.addIob(fromTime, toTime, useIobForScale, 1d);
|
secondGraphData.addIob(fromTime, toTime, useIobForScale, 1d);
|
||||||
if (showCobCheckbox.isChecked())
|
if (showCob)
|
||||||
secondGraphData.addCob(fromTime, toTime, useCobForScale, useCobForScale ? 1d : 0.5d);
|
secondGraphData.addCob(fromTime, toTime, useCobForScale, useCobForScale ? 1d : 0.5d);
|
||||||
if (showDeviationsCheckbox.isChecked())
|
if (showDev)
|
||||||
secondGraphData.addDeviations(fromTime, toTime, useDevForScale, 1d);
|
secondGraphData.addDeviations(fromTime, toTime, useDevForScale, 1d);
|
||||||
if (showRatiosCheckbox.isChecked())
|
if (showRat)
|
||||||
secondGraphData.addRatio(fromTime, toTime, useRatioForScale, 1d);
|
secondGraphData.addRatio(fromTime, toTime, useRatioForScale, 1d);
|
||||||
|
|
||||||
// **** NOW line ****
|
// **** NOW line ****
|
||||||
|
@ -288,7 +282,7 @@ public class HistoryBrowseActivity extends AppCompatActivity {
|
||||||
secondGraphData.addNowLine(pointer);
|
secondGraphData.addNowLine(pointer);
|
||||||
|
|
||||||
// do GUI update
|
// do GUI update
|
||||||
if (showIobCheckbox.isChecked() || showCobCheckbox.isChecked() || showDeviationsCheckbox.isChecked() || showRatiosCheckbox.isChecked()) {
|
if (showIob || showCob || showDev || showRat) {
|
||||||
iobGraph.setVisibility(View.VISIBLE);
|
iobGraph.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
iobGraph.setVisibility(View.GONE);
|
iobGraph.setVisibility(View.GONE);
|
||||||
|
@ -297,4 +291,90 @@ public class HistoryBrowseActivity extends AppCompatActivity {
|
||||||
graphData.performUpdate();
|
graphData.performUpdate();
|
||||||
secondGraphData.performUpdate();
|
secondGraphData.performUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupChartMenu() {
|
||||||
|
chartButton = (ImageButton) findViewById(R.id.overview_chartMenuButton);
|
||||||
|
chartButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
MenuItem item;
|
||||||
|
CharSequence title;
|
||||||
|
SpannableString s;
|
||||||
|
PopupMenu popup = new PopupMenu(v.getContext(), v);
|
||||||
|
|
||||||
|
|
||||||
|
item = popup.getMenu().add(Menu.NONE, OverviewFragment.CHARTTYPE.BAS.ordinal(), Menu.NONE, MainApp.gs(R.string.overview_show_basals));
|
||||||
|
title = item.getTitle();
|
||||||
|
s = new SpannableString(title);
|
||||||
|
s.setSpan(new ForegroundColorSpan(ResourcesCompat.getColor(getResources(), R.color.basal, null)), 0, s.length(), 0);
|
||||||
|
item.setTitle(s);
|
||||||
|
item.setCheckable(true);
|
||||||
|
item.setChecked(showBasal);
|
||||||
|
|
||||||
|
item = popup.getMenu().add(Menu.NONE, OverviewFragment.CHARTTYPE.IOB.ordinal(), Menu.NONE, MainApp.gs(R.string.overview_show_iob));
|
||||||
|
title = item.getTitle();
|
||||||
|
s = new SpannableString(title);
|
||||||
|
s.setSpan(new ForegroundColorSpan(ResourcesCompat.getColor(getResources(), R.color.iob, null)), 0, s.length(), 0);
|
||||||
|
item.setTitle(s);
|
||||||
|
item.setCheckable(true);
|
||||||
|
item.setChecked(showIob);
|
||||||
|
|
||||||
|
item = popup.getMenu().add(Menu.NONE, OverviewFragment.CHARTTYPE.COB.ordinal(), Menu.NONE, MainApp.gs(R.string.overview_show_cob));
|
||||||
|
title = item.getTitle();
|
||||||
|
s = new SpannableString(title);
|
||||||
|
s.setSpan(new ForegroundColorSpan(ResourcesCompat.getColor(getResources(), R.color.cob, null)), 0, s.length(), 0);
|
||||||
|
item.setTitle(s);
|
||||||
|
item.setCheckable(true);
|
||||||
|
item.setChecked(showCob);
|
||||||
|
|
||||||
|
item = popup.getMenu().add(Menu.NONE, OverviewFragment.CHARTTYPE.DEV.ordinal(), Menu.NONE, MainApp.gs(R.string.overview_show_deviations));
|
||||||
|
title = item.getTitle();
|
||||||
|
s = new SpannableString(title);
|
||||||
|
s.setSpan(new ForegroundColorSpan(ResourcesCompat.getColor(getResources(), R.color.deviations, null)), 0, s.length(), 0);
|
||||||
|
item.setTitle(s);
|
||||||
|
item.setCheckable(true);
|
||||||
|
item.setChecked(showDev);
|
||||||
|
|
||||||
|
item = popup.getMenu().add(Menu.NONE, OverviewFragment.CHARTTYPE.SEN.ordinal(), Menu.NONE, MainApp.gs(R.string.overview_show_sensitivity));
|
||||||
|
title = item.getTitle();
|
||||||
|
s = new SpannableString(title);
|
||||||
|
s.setSpan(new ForegroundColorSpan(ResourcesCompat.getColor(getResources(), R.color.ratio, null)), 0, s.length(), 0);
|
||||||
|
item.setTitle(s);
|
||||||
|
item.setCheckable(true);
|
||||||
|
item.setChecked(showRat);
|
||||||
|
|
||||||
|
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
if (item.getItemId() == OverviewFragment.CHARTTYPE.BAS.ordinal()) {
|
||||||
|
showBasal = !item.isChecked();
|
||||||
|
|
||||||
|
} else if (item.getItemId() == OverviewFragment.CHARTTYPE.IOB.ordinal()) {
|
||||||
|
showIob = !item.isChecked();
|
||||||
|
|
||||||
|
} else if (item.getItemId() == OverviewFragment.CHARTTYPE.COB.ordinal()) {
|
||||||
|
showCob = !item.isChecked();
|
||||||
|
|
||||||
|
} else if (item.getItemId() == OverviewFragment.CHARTTYPE.DEV.ordinal()) {
|
||||||
|
showDev = !item.isChecked();
|
||||||
|
|
||||||
|
} else if (item.getItemId() == OverviewFragment.CHARTTYPE.SEN.ordinal()) {
|
||||||
|
showRat = !item.isChecked();
|
||||||
|
}
|
||||||
|
updateGUI("onGraphCheckboxesCheckedChanged");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
chartButton.setImageResource(R.drawable.ic_arrow_drop_up_white_24dp);
|
||||||
|
popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
|
||||||
|
@Override
|
||||||
|
public void onDismiss(PopupMenu menu) {
|
||||||
|
chartButton.setImageResource(R.drawable.ic_arrow_drop_down_white_24dp);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
popup.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,116 +56,6 @@
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="center_horizontal"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:paddingTop="5dp">
|
|
||||||
|
|
||||||
<CheckBox
|
|
||||||
android:id="@+id/overview_showprediction"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:buttonTint="@color/prediction" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/overview_showprediction_label"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:text="@string/predictionshortlabel"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
|
||||||
android:textColor="@color/prediction"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
<CheckBox
|
|
||||||
android:id="@+id/overview_showbasals"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:buttonTint="@color/basal" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/overview_showbasals_label"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:text="@string/basalshortlabel"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
|
||||||
android:textColor="@color/basal"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
<CheckBox
|
|
||||||
android:id="@+id/overview_showiob"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:buttonTint="@color/iob" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/overview_showiob_label"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:text="@string/iob"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
|
||||||
android:textColor="@color/iob"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
|
|
||||||
<CheckBox
|
|
||||||
android:id="@+id/overview_showcob"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:buttonTint="@color/cob" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/overview_showcob_label"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:text="@string/cob"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
|
||||||
android:textColor="@color/cob"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
<CheckBox
|
|
||||||
android:id="@+id/overview_showdeviations"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:buttonTint="@color/deviations" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/overview_showdeviations_label"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:text="@string/dev"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
|
||||||
android:textColor="@color/deviations"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
<CheckBox
|
|
||||||
android:id="@+id/overview_showratios"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/overview_showratios_label"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:text="@string/ratio_short"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -176,11 +66,26 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<com.jjoe64.graphview.GraphView
|
<RelativeLayout
|
||||||
android:id="@+id/historyybrowse_bggraph"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_weight="1" />
|
android:layout_weight="1">
|
||||||
|
|
||||||
|
<com.jjoe64.graphview.GraphView
|
||||||
|
android:id="@+id/historyybrowse_bggraph"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/overview_chartMenuButton"
|
||||||
|
android:layout_width="30dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_alignParentTop="true"
|
||||||
|
android:paddingTop="5dp"
|
||||||
|
app:srcCompat="@drawable/ic_arrow_drop_down_white_24dp" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
<com.jjoe64.graphview.GraphView
|
<com.jjoe64.graphview.GraphView
|
||||||
android:id="@+id/historybrowse_iobgraph"
|
android:id="@+id/historybrowse_iobgraph"
|
||||||
|
|
Loading…
Reference in a new issue