use of com.health.openscale.gui.views.MeasurementView in project openScale by oliexdev.
the class DataEntryActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dataentry);
Toolbar toolbar = (Toolbar) findViewById(R.id.dataEntryToolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("");
context = this;
tableLayoutDataEntry = (TableLayout) findViewById(R.id.tableLayoutDataEntry);
dataEntryMeasurements = MeasurementView.getMeasurementList(context, MeasurementView.DateTimeOrder.LAST);
txtDataNr = (TextView) findViewById(R.id.txtDataNr);
btnLeft = (Button) findViewById(R.id.btnLeft);
btnRight = (Button) findViewById(R.id.btnRight);
btnLeft.setVisibility(View.INVISIBLE);
btnRight.setVisibility(View.INVISIBLE);
btnLeft.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
moveLeft();
}
});
btnRight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
moveRight();
}
});
final MeasurementView.MeasurementViewMode mode = isAddActivity() ? MeasurementView.MeasurementViewMode.ADD : MeasurementView.MeasurementViewMode.VIEW;
for (MeasurementView measurement : dataEntryMeasurements) {
measurement.setEditMode(mode);
}
updateOnView();
onMeasurementViewUpdateListener updateListener = new onMeasurementViewUpdateListener();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
final boolean expand = isAddActivity() ? false : prefs.getBoolean(PREF_EXPAND, true);
for (MeasurementView measurement : dataEntryMeasurements) {
tableLayoutDataEntry.addView(measurement);
measurement.setOnUpdateListener(updateListener);
measurement.setExpand(expand);
}
}
use of com.health.openscale.gui.views.MeasurementView in project openScale by oliexdev.
the class OverviewFragment method updateLastLineChart.
private void updateLastLineChart(List<ScaleMeasurement> scaleMeasurementList) {
final Calendar now = Calendar.getInstance();
Calendar histCalendar = Calendar.getInstance();
scaleMeasurementLastDays = new ArrayList<>();
List<AxisValue> axisValues = new ArrayList<>();
int max_i = Math.min(7, scaleMeasurementList.size());
for (int i = 0; i < max_i; ++i) {
ScaleMeasurement measurement = scaleMeasurementList.get(max_i - i - 1);
scaleMeasurementLastDays.add(measurement);
histCalendar.setTime(measurement.getDateTime());
int days = DateTimeHelpers.daysBetween(now, histCalendar);
String label = getResources().getQuantityString(R.plurals.label_days, Math.abs(days), days);
axisValues.add(new AxisValue(i, label.toCharArray()));
}
List<Line> diagramLineList = new ArrayList<>();
for (MeasurementView view : measurementViews) {
if (!view.isVisible() || !view.getSettings().isInOverviewGraph() || !(view instanceof FloatMeasurementView)) {
continue;
}
FloatMeasurementView measurementView = (FloatMeasurementView) view;
Stack<PointValue> valuesStack = new Stack<PointValue>();
for (int i = 0; i < max_i; ++i) {
ScaleMeasurement measurement = scaleMeasurementList.get(max_i - i - 1);
measurementView.loadFrom(measurement, null);
if (measurementView.getValue() != 0.0f) {
valuesStack.push(new PointValue(i, measurementView.getValue()));
}
}
diagramLineList.add(new Line(valuesStack).setColor(measurementView.getColor()).setHasLabels(prefs.getBoolean("labelsEnable", true)).setHasPoints(prefs.getBoolean("pointsEnable", true)).setFormatter(new SimpleLineChartValueFormatter(1)));
}
LineChartData lineData = new LineChartData(diagramLineList);
lineData.setAxisXBottom(new Axis(axisValues).setHasLines(true).setTextColor(txtTitleLastMeasurement.getCurrentTextColor()));
lineData.setAxisYLeft(new Axis().setHasLines(true).setMaxLabelChars(5).setTextColor(txtTitleLastMeasurement.getCurrentTextColor()));
lineChartLast.setLineChartData(lineData);
lineChartLast.setViewportCalculationEnabled(true);
lineChartLast.setZoomEnabled(false);
}
use of com.health.openscale.gui.views.MeasurementView in project openScale by oliexdev.
the class OverviewFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
overviewView = inflater.inflate(R.layout.fragment_overview, container, false);
userLineSeparator = overviewView.findViewById(R.id.userLineSeparator);
context = overviewView.getContext();
txtTitleUser = (TextView) overviewView.findViewById(R.id.txtTitleUser);
txtTitleLastMeasurement = (TextView) overviewView.findViewById(R.id.txtTitleLastMeasurment);
tableOverviewLayout = (TableLayout) overviewView.findViewById(R.id.tableLayoutMeasurements);
pieChartLast = (PieChartView) overviewView.findViewById(R.id.pieChartLast);
lineChartLast = (LineChartView) overviewView.findViewById(R.id.lineChartLast);
spinUser = (Spinner) overviewView.findViewById(R.id.spinUser);
lineChartLast.setOnValueTouchListener(new LineChartTouchListener());
pieChartLast.setOnValueTouchListener(new PieChartLastTouchListener());
pieChartLast.setChartRotationEnabled(false);
measurementViews = MeasurementView.getMeasurementList(getContext(), MeasurementView.DateTimeOrder.NONE);
for (MeasurementView measurement : measurementViews) {
tableOverviewLayout.addView(measurement);
}
userSelectedData = null;
spinUserAdapter = new ArrayAdapter<>(overviewView.getContext(), R.layout.support_simple_spinner_dropdown_item, new ArrayList<String>());
spinUser.setAdapter(spinUserAdapter);
// Set item select listener after spinner is created because otherwise item listener fires a lot!?!?
spinUser.post(new Runnable() {
public void run() {
spinUser.setOnItemSelectedListener(new spinUserSelectionListener());
updateUserSelection();
}
});
txtTitleUser.setText(getResources().getString(R.string.label_title_user).toUpperCase());
txtTitleLastMeasurement.setText(getResources().getString(R.string.label_title_last_measurement).toUpperCase());
prefs = PreferenceManager.getDefaultSharedPreferences(overviewView.getContext());
OpenScale.getInstance(getContext()).registerFragment(this);
return overviewView;
}
use of com.health.openscale.gui.views.MeasurementView in project openScale by oliexdev.
the class OverviewFragment method updateOnView.
@Override
public void updateOnView(List<ScaleMeasurement> scaleMeasurementList) {
if (scaleMeasurementList.isEmpty()) {
lastScaleMeasurement = new ScaleMeasurement();
} else if (userSelectedData != null) {
lastScaleMeasurement = userSelectedData;
} else {
lastScaleMeasurement = scaleMeasurementList.get(0);
}
ScaleMeasurement[] tupleScaleData = OpenScale.getInstance(context).getTupleScaleData(lastScaleMeasurement.getId());
ScaleMeasurement prevScaleMeasurement = tupleScaleData[0];
updateUserSelection();
updateLastPieChart();
updateLastLineChart(scaleMeasurementList);
for (MeasurementView measurement : measurementViews) {
measurement.loadFrom(lastScaleMeasurement, prevScaleMeasurement);
}
}
use of com.health.openscale.gui.views.MeasurementView in project openScale by oliexdev.
the class OverviewFragment method updateLastPieChart.
private void updateLastPieChart() {
List<SliceValue> arcValuesLast = new ArrayList<>();
for (MeasurementView view : measurementViews) {
if (view instanceof FloatMeasurementView) {
FloatMeasurementView measurementView = (FloatMeasurementView) view;
if (measurementView instanceof BMRMeasurementView) {
continue;
}
measurementView.loadFrom(lastScaleMeasurement, null);
if (measurementView.getValue() != 0) {
arcValuesLast.add(new SliceValue(measurementView.getValue(), measurementView.getColor()));
}
}
}
final Converters.WeightUnit unit = currentScaleUser.getScaleUnit();
PieChartData pieChartData = new PieChartData(arcValuesLast);
pieChartData.setHasLabels(false);
pieChartData.setHasCenterCircle(true);
pieChartData.setCenterText1(String.format("%.2f %s", lastScaleMeasurement.getConvertedWeight(unit), unit.toString()));
pieChartData.setCenterText2(DateFormat.getDateInstance(DateFormat.MEDIUM).format(lastScaleMeasurement.getDateTime()));
pieChartData.setCenterText1Color(txtTitleLastMeasurement.getCurrentTextColor());
pieChartData.setCenterText2Color(txtTitleLastMeasurement.getCurrentTextColor());
if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE || (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {
pieChartData.setCenterText1FontSize(20);
pieChartData.setCenterText2FontSize(14);
} else {
pieChartData.setCenterText1FontSize(15);
pieChartData.setCenterText2FontSize(12);
pieChartData.setValueLabelTextSize(12);
}
pieChartLast.setPieChartData(pieChartData);
}
Aggregations