Search in sources :

Example 6 with MeasurementView

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);
    }
}
Also used : WeightMeasurementView(com.health.openscale.gui.measurement.WeightMeasurementView) MeasurementView(com.health.openscale.gui.measurement.MeasurementView) Preference(androidx.preference.Preference)

Example 7 with MeasurementView

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;
}
Also used : ChartMeasurementView(com.health.openscale.gui.measurement.ChartMeasurementView) MeasurementView(com.health.openscale.gui.measurement.MeasurementView) ArrayList(java.util.ArrayList) MenuItem(android.view.MenuItem) ChartMeasurementView(com.health.openscale.gui.measurement.ChartMeasurementView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) ChartActionBarView(com.health.openscale.gui.measurement.ChartActionBarView) TextView(android.widget.TextView) MeasurementView(com.health.openscale.gui.measurement.MeasurementView) OnBackPressedCallback(androidx.activity.OnBackPressedCallback) ScaleMeasurement(com.health.openscale.core.datatypes.ScaleMeasurement) ArrayList(java.util.ArrayList) List(java.util.List) ImageView(android.widget.ImageView) ChartMeasurementView(com.health.openscale.gui.measurement.ChartMeasurementView) TableLayout(android.widget.TableLayout) PopupMenu(android.widget.PopupMenu)

Example 8 with MeasurementView

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);
}
Also used : UserMeasurementView(com.health.openscale.gui.measurement.UserMeasurementView) UserMeasurementView(com.health.openscale.gui.measurement.UserMeasurementView) MeasurementView(com.health.openscale.gui.measurement.MeasurementView) TableRow(android.widget.TableRow) ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView)

Aggregations

MeasurementView (com.health.openscale.gui.measurement.MeasurementView)8 ScaleMeasurement (com.health.openscale.core.datatypes.ScaleMeasurement)5 ArrayList (java.util.ArrayList)5 Intent (android.content.Intent)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 TableRow (android.widget.TableRow)2 OnBackPressedCallback (androidx.activity.OnBackPressedCallback)2 OpenScale (com.health.openscale.core.OpenScale)2 ChartMeasurementView (com.health.openscale.gui.measurement.ChartMeasurementView)2 UserMeasurementView (com.health.openscale.gui.measurement.UserMeasurementView)2 WeightMeasurementView (com.health.openscale.gui.measurement.WeightMeasurementView)2 List (java.util.List)2 PendingIntent (android.app.PendingIntent)1 SharedPreferences (android.content.SharedPreferences)1 Bundle (android.os.Bundle)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 MenuItem (android.view.MenuItem)1 AdapterView (android.widget.AdapterView)1 ArrayAdapter (android.widget.ArrayAdapter)1