use of com.health.openscale.gui.measurement.MeasurementView in project openScale by oliexdev.
the class MeasurementPreferences method updateMeasurementPreferences.
private void updateMeasurementPreferences() {
measurementCategory.removeAll();
List<MeasurementView> measurementViews = MeasurementView.getMeasurementList(getActivity(), MeasurementView.DateTimeOrder.NONE);
for (MeasurementView measurement : measurementViews) {
Preference preference = new MeasurementOrderPreference(getActivity(), measurementCategory, measurement);
measurementCategory.addPreference(preference);
}
}
use of com.health.openscale.gui.measurement.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);
prefs = PreferenceManager.getDefaultSharedPreferences(overviewView.getContext());
txtTitleUser = overviewView.findViewById(R.id.txtTitleUser);
chartView = overviewView.findViewById(R.id.chartView);
chartView.setOnChartValueSelectedListener(new onChartSelectedListener());
chartView.setProgressBar(overviewView.findViewById(R.id.progressBar));
chartView.setIsInGraphKey(false);
chartActionBarView = overviewView.findViewById(R.id.chartActionBar);
chartActionBarView.setIsInGraphKey(false);
chartActionBarView.setOnActionClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
chartView.refreshMeasurementList();
updateChartView();
}
});
spinUser = overviewView.findViewById(R.id.spinUser);
ImageView optionMenu = overviewView.findViewById(R.id.rangeOptionMenu);
optionMenu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
rangePopupMenu.show();
}
});
rangePopupMenu = new PopupMenu(getContext(), optionMenu);
rangePopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case R.id.enableChartActionBar:
if (item.isChecked()) {
item.setChecked(false);
prefs.edit().putBoolean("enableOverviewChartActionBar", false).apply();
chartActionBarView.setVisibility(View.GONE);
} else {
item.setChecked(true);
prefs.edit().putBoolean("enableOverviewChartActionBar", true).apply();
chartActionBarView.setVisibility(View.VISIBLE);
}
return true;
case R.id.menu_range_day:
prefs.edit().putInt("selectRangeMode", ChartMeasurementView.ViewMode.DAY_OF_ALL.ordinal()).commit();
break;
case R.id.menu_range_week:
prefs.edit().putInt("selectRangeMode", ChartMeasurementView.ViewMode.WEEK_OF_ALL.ordinal()).commit();
break;
case R.id.menu_range_month:
prefs.edit().putInt("selectRangeMode", ChartMeasurementView.ViewMode.MONTH_OF_ALL.ordinal()).commit();
break;
case R.id.menu_range_year:
prefs.edit().putInt("selectRangeMode", ChartMeasurementView.ViewMode.YEAR_OF_ALL.ordinal()).commit();
}
item.setChecked(true);
// TODO HACK to refresh graph; graph.invalidate and notfiydatachange is not enough!?
getActivity().recreate();
return true;
}
});
rangePopupMenu.getMenuInflater().inflate(R.menu.overview_menu, rangePopupMenu.getMenu());
ChartMeasurementView.ViewMode selectedRangePos = ChartMeasurementView.ViewMode.values()[prefs.getInt("selectRangeMode", ChartMeasurementView.ViewMode.DAY_OF_ALL.ordinal())];
switch(selectedRangePos) {
case DAY_OF_ALL:
rangePopupMenu.getMenu().findItem(R.id.menu_range_day).setChecked(true);
break;
case WEEK_OF_ALL:
rangePopupMenu.getMenu().findItem(R.id.menu_range_week).setChecked(true);
break;
case MONTH_OF_ALL:
rangePopupMenu.getMenu().findItem(R.id.menu_range_month).setChecked(true);
break;
case YEAR_OF_ALL:
rangePopupMenu.getMenu().findItem(R.id.menu_range_year).setChecked(true);
break;
}
MenuItem enableMeasurementBar = rangePopupMenu.getMenu().findItem(R.id.enableChartActionBar);
enableMeasurementBar.setChecked(prefs.getBoolean("enableOverviewChartActionBar", false));
if (enableMeasurementBar.isChecked()) {
chartActionBarView.setVisibility(View.VISIBLE);
} else {
chartActionBarView.setVisibility(View.GONE);
}
lastMeasurementViews = MeasurementView.getMeasurementList(getContext(), MeasurementView.DateTimeOrder.LAST);
TableLayout tableOverviewLayout = overviewView.findViewById(R.id.tableLayoutMeasurements);
for (MeasurementView measurement : lastMeasurementViews) {
tableOverviewLayout.addView(measurement);
}
spinUserAdapter = new ArrayAdapter<>(overviewView.getContext(), R.layout.spinner_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();
}
});
showEntry = overviewView.findViewById(R.id.showEntry);
showEntry.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OverviewFragmentDirections.ActionNavOverviewToNavDataentry action = OverviewFragmentDirections.actionNavOverviewToNavDataentry();
action.setMeasurementId(markedMeasurement.getId());
action.setMode(MeasurementEntryFragment.DATA_ENTRY_MODE.VIEW);
Navigation.findNavController(getActivity(), R.id.nav_host_fragment).navigate(action);
}
});
editEntry = overviewView.findViewById(R.id.editEntry);
editEntry.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OverviewFragmentDirections.ActionNavOverviewToNavDataentry action = OverviewFragmentDirections.actionNavOverviewToNavDataentry();
action.setMeasurementId(markedMeasurement.getId());
action.setMode(MeasurementEntryFragment.DATA_ENTRY_MODE.EDIT);
Navigation.findNavController(getActivity(), R.id.nav_host_fragment).navigate(action);
}
});
deleteEntry = overviewView.findViewById(R.id.deleteEntry);
deleteEntry.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
deleteMeasurement();
}
});
showEntry.setEnabled(false);
editEntry.setEnabled(false);
deleteEntry.setEnabled(false);
chartView.animateY(700);
OpenScale.getInstance().getScaleMeasurementsLiveData().observe(getViewLifecycleOwner(), new Observer<List<ScaleMeasurement>>() {
@Override
public void onChanged(List<ScaleMeasurement> scaleMeasurements) {
updateOnView(scaleMeasurements);
}
});
OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
requireActivity().finish();
}
};
requireActivity().getOnBackPressedDispatcher().addCallback(getViewLifecycleOwner(), onBackPressedCallback);
return overviewView;
}
use of com.health.openscale.gui.measurement.MeasurementView in project openScale by oliexdev.
the class TableFragment method updateOnView.
public void updateOnView(List<ScaleMeasurement> scaleMeasurementList) {
tableHeaderView.removeAllViews();
final int iconHeight = pxImageDp(20);
ArrayList<MeasurementView> visibleMeasurements = new ArrayList<>();
for (MeasurementView measurement : measurementViews) {
if (!measurement.isVisible() || measurement instanceof UserMeasurementView) {
continue;
}
ImageView headerIcon = new ImageView(tableView.getContext());
headerIcon.setImageDrawable(measurement.getIcon());
headerIcon.setColorFilter(ColorUtil.getTintColor(tableView.getContext()));
headerIcon.setLayoutParams(new TableRow.LayoutParams(0, iconHeight, 1));
headerIcon.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
tableHeaderView.addView(headerIcon);
visibleMeasurements.add(measurement);
}
adapter.setMeasurements(visibleMeasurements, scaleMeasurementList);
}
Aggregations