diff --git a/app/src/main/java/hrv/band/app/device/ConnectionManager.java b/app/src/main/java/hrv/band/app/device/ConnectionManager.java new file mode 100644 index 0000000..467fe3f --- /dev/null +++ b/app/src/main/java/hrv/band/app/device/ConnectionManager.java @@ -0,0 +1,77 @@ +package hrv.band.app.device; + +import android.app.Activity; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; +import android.support.annotation.NonNull; + +import hrv.band.app.device.antplus.AntPlusRRDataDevice; +import hrv.band.app.device.msband.MSBandRRIntervalDevice; + +/** + * Copyright (c) 2017 + * Created by Thomas Czogalik on 23.04.2017 + */ +public class ConnectionManager { + private Activity activity; + private SharedPreferences sharedPreferences; + + private static final String SELECTED_DEVICE_ID = "selected_device_id"; + + public ConnectionManager(Activity activity) { + this.activity = activity; + this.sharedPreferences = PreferenceManager.getDefaultSharedPreferences(activity); + } + + /** + * Connects to ms band. + */ + public HRVRRIntervalDevice connectToMSBand() { + setDevice(Device.MSBAND); + return connectToIntervalDevice(); + } + + @NonNull + private HRVRRIntervalDevice connectToIntervalDevice() { + HRVRRIntervalDevice hrvRRIntervalDevice = getDevice(); + hrvRRIntervalDevice.connect(); + return hrvRRIntervalDevice; + } + + /** + * Connects to ant+ device. + */ + public HRVRRIntervalDevice connectToAnt() { + setDevice(Device.ANT); + return connectToIntervalDevice(); + } + + /** + * Disconnects connected device. + */ + public HRVRRIntervalDevice disconnectDevices(HRVRRIntervalDevice hrvRRIntervalDevice) { + setDevice(Device.NONE); + if (hrvRRIntervalDevice != null) { + hrvRRIntervalDevice.notifyDeviceStatusChanged(HRVDeviceStatus.DISCONNECTED); + } + return null; + } + + public HRVRRIntervalDevice getDevice() { + Device device = Device.values()[sharedPreferences.getInt(SELECTED_DEVICE_ID, 0)]; + switch (device) { + case MSBAND: + return new MSBandRRIntervalDevice(activity); + case ANT: + return new AntPlusRRDataDevice(activity); + default: + return null; + } + } + + private void setDevice(Device device) { + SharedPreferences.Editor prefsEditor = sharedPreferences.edit(); + prefsEditor.putInt(SELECTED_DEVICE_ID, device.ordinal()); + prefsEditor.apply(); + } +} diff --git a/app/src/main/java/hrv/band/app/device/Device.java b/app/src/main/java/hrv/band/app/device/Device.java new file mode 100644 index 0000000..5be2d0d --- /dev/null +++ b/app/src/main/java/hrv/band/app/device/Device.java @@ -0,0 +1,12 @@ +package hrv.band.app.device; + +/** + * Copyright (c) 2017 + * Created by Thomas on 23.04.2017. + * + * Possible devices the user can select. + */ + +public enum Device { + NONE, MSBAND, ANT +} diff --git a/app/src/main/java/hrv/band/app/device/antplus/AntPlusRRDataDevice.java b/app/src/main/java/hrv/band/app/device/antplus/AntPlusRRDataDevice.java index 5095685..339f42a 100644 --- a/app/src/main/java/hrv/band/app/device/antplus/AntPlusRRDataDevice.java +++ b/app/src/main/java/hrv/band/app/device/antplus/AntPlusRRDataDevice.java @@ -1,7 +1,6 @@ package hrv.band.app.device.antplus; import android.app.Activity; -import android.content.Context; import com.dsi.ant.plugins.antplus.pcc.AntPlusHeartRatePcc; import com.dsi.ant.plugins.antplus.pcc.defines.DeviceState; @@ -25,12 +24,10 @@ public class AntPlusRRDataDevice AntPluginPcc.IPluginAccessResultReceiver, AntPlusHeartRatePcc.ICalculatedRrIntervalReceiver { - private final Context context; private final Activity activity; private AntPlusHeartRatePcc wgtplc; - public AntPlusRRDataDevice(Context context, Activity activity) { - this.context = context; + public AntPlusRRDataDevice(Activity activity) { this.activity = activity; } @@ -107,7 +104,7 @@ public void connect() { activity.runOnUiThread(new Runnable() { @Override public void run() { - AntPlusHeartRatePcc.requestAccess(activity, context, helper, helper); + AntPlusHeartRatePcc.requestAccess(activity, activity.getApplicationContext(), helper, helper); } }); } diff --git a/app/src/main/java/hrv/band/app/ui/presenter/IMainPresenter.java b/app/src/main/java/hrv/band/app/ui/presenter/IMainPresenter.java new file mode 100644 index 0000000..387a1a5 --- /dev/null +++ b/app/src/main/java/hrv/band/app/ui/presenter/IMainPresenter.java @@ -0,0 +1,11 @@ +package hrv.band.app.ui.presenter; + +/** + * Copyright (c) 2017 + * Created by Thomas on 23.04.2017. + */ + +public interface IMainPresenter { + boolean agreedToDisclaimer(); + void handleNavBar(int id); +} diff --git a/app/src/main/java/hrv/band/app/ui/presenter/IMeasuringPresenter.java b/app/src/main/java/hrv/band/app/ui/presenter/IMeasuringPresenter.java new file mode 100644 index 0000000..cd55c06 --- /dev/null +++ b/app/src/main/java/hrv/band/app/ui/presenter/IMeasuringPresenter.java @@ -0,0 +1,17 @@ +package hrv.band.app.ui.presenter; + +import java.util.Date; +import java.util.List; + +import hrv.band.app.model.Measurement; + +/** + * Copyright (c) 2017 + * Created by Thomas Czogalik on 23.04.2017 + */ + +public interface IMeasuringPresenter { + int getDuration(); + + Measurement createMeasurement(List rrInterval, Date time); +} diff --git a/app/src/main/java/hrv/band/app/ui/presenter/MainPresenter.java b/app/src/main/java/hrv/band/app/ui/presenter/MainPresenter.java new file mode 100644 index 0000000..b7d553d --- /dev/null +++ b/app/src/main/java/hrv/band/app/ui/presenter/MainPresenter.java @@ -0,0 +1,66 @@ +package hrv.band.app.ui.presenter; + +import android.content.SharedPreferences; +import android.preference.PreferenceManager; + +import hrv.band.app.R; +import hrv.band.app.ui.view.activity.IMainView; +import hrv.band.app.ui.view.activity.ImprintActivity; +import hrv.band.app.ui.view.activity.IntroActivity; +import hrv.band.app.ui.view.activity.SettingsActivity; +import hrv.band.app.ui.view.activity.WebActivity; +import hrv.band.app.ui.view.fragment.DisclaimerDialogFragment; + +import static hrv.band.app.ui.view.activity.web.WebsiteUrls.WEBSITE_PRIVACY_URL; +import static hrv.band.app.ui.view.activity.web.WebsiteUrls.WEBSITE_URL; + +/** + * Copyright (c) 2017 + * Created by Thomas on 23.04.2017. + */ + +public class MainPresenter implements IMainPresenter { + private IMainView mainView; + + public MainPresenter(IMainView mainView) { + this.mainView = mainView; + } + + @Override + public boolean agreedToDisclaimer() { + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mainView.getMainActivity()); + return sharedPreferences.getBoolean(DisclaimerDialogFragment.DISCLAIMER_AGREEMENT, false); + } + + @Override + public void handleNavBar(int id) { + switch (id) { + case R.id.menu_help: + mainView.startActivity(IntroActivity.class); + break; + case R.id.menu_website: + mainView.startActivity(WebActivity.class, WebActivity.WEBSITE_URL_ID, WEBSITE_URL); + break; + case R.id.menu_share: + mainView.openShareIntent(); + break; + case R.id.menu_privacy: + mainView.startActivity(WebActivity.class, WebActivity.WEBSITE_URL_ID, WEBSITE_PRIVACY_URL); + break; + case R.id.menu_feedback: + mainView.startFeedbackDialog(); + break; + case R.id.menu_imprint: + mainView.startActivity(ImprintActivity.class); + break; + case R.id.menu_rate: + mainView.rateApp(); + break; + case R.id.menu_Settings: + mainView.startActivity(SettingsActivity.class); + break; + default: + break; + } + } +} diff --git a/app/src/main/java/hrv/band/app/ui/presenter/MeasuringPresenter.java b/app/src/main/java/hrv/band/app/ui/presenter/MeasuringPresenter.java new file mode 100644 index 0000000..007e195 --- /dev/null +++ b/app/src/main/java/hrv/band/app/ui/presenter/MeasuringPresenter.java @@ -0,0 +1,49 @@ +package hrv.band.app.ui.presenter; + +import android.content.SharedPreferences; +import android.preference.PreferenceManager; + +import java.util.Date; +import java.util.List; + +import common.ArrayUtils; +import hrv.RRData; +import hrv.band.app.model.Measurement; +import hrv.band.app.ui.view.fragment.IMeasuringView; + +/** + * Copyright (c) 2017 + * Created by Thomas Czogalik on 23.04.2017 + */ + +public class MeasuringPresenter implements IMeasuringPresenter { + private SharedPreferences sharedPreferences; + + private static final String RECORDING_LENGTH_ID = "recording_length"; + + + public MeasuringPresenter(IMeasuringView measuringView) { + this.sharedPreferences = PreferenceManager.getDefaultSharedPreferences(measuringView.getParentActivity()); + } + + @Override + public int getDuration() { + //TODO: int statt string + String durationPrefVal = sharedPreferences.getString(RECORDING_LENGTH_ID, "90"); + return Integer.parseInt(durationPrefVal) * 1000; + } + + @Override + public Measurement createMeasurement(List rrInterval, Date time) { + //start calculation + double[] rrArray = convertListToDouble(rrInterval); + + RRData.createFromRRInterval(rrArray, units.TimeUnit.SECOND); + Measurement.MeasurementBuilder measurementBuilder = Measurement.from(time, rrArray); + return measurementBuilder.build(); + } + + private double[] convertListToDouble(List doubles) { + return ArrayUtils.toPrimitiveIgnoreNull(doubles.toArray(new Double[0])); + } +} diff --git a/app/src/main/java/hrv/band/app/ui/view/activity/IMainView.java b/app/src/main/java/hrv/band/app/ui/view/activity/IMainView.java new file mode 100644 index 0000000..aa9a846 --- /dev/null +++ b/app/src/main/java/hrv/band/app/ui/view/activity/IMainView.java @@ -0,0 +1,25 @@ +package hrv.band.app.ui.view.activity; + +import android.app.Activity; + +/** + * Copyright (c) 2017 + * Created by Thomas on 23.04.2017. + */ + +public interface IMainView { + void startActivity(Class activity); + + void startActivity(Class activity, String extraId, String extra); + + void startFeedbackDialog(); + + Activity getMainActivity(); + + void openShareIntent(); + + void rateApp(); + + void stopMeasuring(); + +} diff --git a/app/src/main/java/hrv/band/app/ui/view/activity/MainActivity.java b/app/src/main/java/hrv/band/app/ui/view/activity/MainActivity.java index a41b326..4f9faaa 100644 --- a/app/src/main/java/hrv/band/app/ui/view/activity/MainActivity.java +++ b/app/src/main/java/hrv/band/app/ui/view/activity/MainActivity.java @@ -1,8 +1,8 @@ package hrv.band.app.ui.view.activity; +import android.app.Activity; import android.content.ActivityNotFoundException; import android.content.Intent; -import android.content.SharedPreferences; import android.content.res.Resources; import android.net.Uri; import android.os.Build; @@ -26,15 +26,15 @@ import java.util.List; import hrv.band.app.R; +import hrv.band.app.ui.presenter.IMainPresenter; +import hrv.band.app.ui.presenter.MainPresenter; import hrv.band.app.ui.view.adapter.SectionPagerAdapter; import hrv.band.app.ui.view.fragment.DisclaimerDialogFragment; import hrv.band.app.ui.view.fragment.FeedbackDialogFragment; +import hrv.band.app.ui.view.fragment.IMeasuringView; import hrv.band.app.ui.view.fragment.MeasuringFragment; import hrv.band.app.ui.view.fragment.OverviewFragment; -import static hrv.band.app.ui.view.activity.web.WebsiteUrls.WEBSITE_PRIVACY_URL; -import static hrv.band.app.ui.view.activity.web.WebsiteUrls.WEBSITE_URL; - /** * Copyright (c) 2017 * Created by Thomas Czogalik on 19.01.2017 @@ -42,15 +42,20 @@ * This Activity is the main Activity and holds the measurement and overview Fragment. */ public class MainActivity extends AppCompatActivity - implements NavigationView.OnNavigationItemSelectedListener { + implements NavigationView.OnNavigationItemSelectedListener, IMainView { public static final String HRV_PARAMETER_ID = "HRV_PARAMETER"; public static final String HRV_VALUE = "hrv_rr_value"; + private IMainPresenter presenter; + private IMeasuringView measuringView; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + presenter = new MainPresenter(this); + handleDisclaimer(); //Needed to set default values @@ -75,7 +80,8 @@ protected void onCreate(Bundle savedInstanceState) { //Fragment List fragments = new ArrayList<>(); - fragments.add(MeasuringFragment.newInstance()); + measuringView = MeasuringFragment.newInstance(); + fragments.add((Fragment) measuringView); fragments.add(OverviewFragment.newInstance()); SectionPagerAdapter mSectionsPagerAdapter = new SectionPagerAdapter(getSupportFragmentManager(), fragments, getPageTitles()); @@ -109,12 +115,8 @@ public void onBackPressed() { //Close the app, if disclaimer has not yet been accepted int backStackCount = getFragmentManager().getBackStackEntryCount(); - if (backStackCount != 0) { - - SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); - if (!sharedPreferences.getBoolean(DisclaimerDialogFragment.DISCLAIMER_AGREEMENT, false)) { - finish(); - } + if (backStackCount != 0 && !presenter.agreedToDisclaimer()) { + finish(); } //If the Navigation Drawer is opened, a backPressed closes the Navigation Drawer. @@ -138,43 +140,12 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { // Handle navigation view item clicks here. - int id = item.getItemId(); - switch (id) { - case R.id.menu_help: - startActivity(new Intent(this, IntroActivity.class)); - break; - case R.id.menu_website: { - Intent webIntent = new Intent(this, WebActivity.class); - webIntent.putExtra(WebActivity.WEBSITE_URL_ID, WEBSITE_URL); - startActivity(webIntent); - break; - } - case R.id.menu_share: - openShareIntent(); - break; - case R.id.menu_privacy: { - Intent webIntent = new Intent(this, WebActivity.class); - webIntent.putExtra(WebActivity.WEBSITE_URL_ID, WEBSITE_PRIVACY_URL); - startActivity(webIntent); - break; - } - case R.id.menu_feedback: - FeedbackDialogFragment.newInstance().show(getSupportFragmentManager(), "Feedback"); - break; - case R.id.menu_imprint: - startActivity(new Intent(this, ImprintActivity.class)); - break; - case R.id.menu_rate: - rateApp(); - break; - case R.id.menu_Settings: - startActivity(new Intent(this, SettingsActivity.class)); - break; - } - DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); - assert drawer != null; + presenter.handleNavBar(item.getItemId()); - drawer.closeDrawer(GravityCompat.START); + DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); + if (drawer != null) { + drawer.closeDrawer(GravityCompat.START); + } return true; } @@ -182,7 +153,8 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) { * Opens play store hence the user can rate the app. * http://stackoverflow.com/questions/10816757/rate-this-app-link-in-google-play-store-app-on-the-phone */ - private void rateApp() { + @Override + public void rateApp() { Uri uri = Uri.parse("market://details?id=" + this.getPackageName()); Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri); // To count with Play market backstack, After pressing back button, @@ -204,7 +176,8 @@ private void rateApp() { /** * Opens dialog which lists all apps the user can share a message with. */ - private void openShareIntent() { + @Override + public void openShareIntent() { Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); sharingIntent.setType("text/plain"); Resources resources = getResources(); @@ -217,12 +190,10 @@ private void openShareIntent() { /** * Stops the measurement. */ + @Override public void stopMeasuring() { - List fragments = getSupportFragmentManager().getFragments(); - for (Fragment fragment : fragments) { - if (fragment instanceof MeasuringFragment) { - ((MeasuringFragment) fragment).stopMeasuring(); - } + if (measuringView != null) { + measuringView.stopMeasuring(); } } @@ -231,11 +202,31 @@ public void stopMeasuring() { * disclaimer it will not open again. */ private void handleDisclaimer() { - SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); - - if (!sharedPreferences.getBoolean(DisclaimerDialogFragment.DISCLAIMER_AGREEMENT, false)) { + if (!presenter.agreedToDisclaimer()) { DisclaimerDialogFragment disclaimerDialogFragment = new DisclaimerDialogFragment(); disclaimerDialogFragment.show(getFragmentManager(), "dialog"); } } + + @Override + public void startActivity(Class activity) { + startActivity(new Intent(this, activity)); + } + + @Override + public void startActivity(Class activity, String extraId, String extra) { + Intent intent = new Intent(this, activity); + intent.putExtra(extraId, extra); + startActivity(intent); + } + + @Override + public void startFeedbackDialog() { + FeedbackDialogFragment.newInstance().show(getSupportFragmentManager(), "Feedback"); + } + + @Override + public Activity getMainActivity() { + return this; + } } diff --git a/app/src/main/java/hrv/band/app/ui/view/fragment/CancelMeasuringDialogFragment.java b/app/src/main/java/hrv/band/app/ui/view/fragment/CancelMeasuringDialogFragment.java index 9bd9810..a0f50bd 100644 --- a/app/src/main/java/hrv/band/app/ui/view/fragment/CancelMeasuringDialogFragment.java +++ b/app/src/main/java/hrv/band/app/ui/view/fragment/CancelMeasuringDialogFragment.java @@ -10,7 +10,7 @@ import android.widget.TextView; import hrv.band.app.R; -import hrv.band.app.ui.view.activity.MainActivity; +import hrv.band.app.ui.view.activity.IMainView; /** * Copyright (c) 2017 @@ -38,8 +38,8 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { @Override public void onClick(DialogInterface dialog, int id) { Activity activity = getActivity(); - if (activity instanceof MainActivity) { - ((MainActivity) getActivity()).stopMeasuring(); + if (activity instanceof IMainView) { + ((IMainView) getActivity()).stopMeasuring(); } } }) diff --git a/app/src/main/java/hrv/band/app/ui/view/fragment/IMeasuringView.java b/app/src/main/java/hrv/band/app/ui/view/fragment/IMeasuringView.java new file mode 100644 index 0000000..195a147 --- /dev/null +++ b/app/src/main/java/hrv/band/app/ui/view/fragment/IMeasuringView.java @@ -0,0 +1,38 @@ +package hrv.band.app.ui.view.fragment; + +import android.app.Activity; + +import hrv.band.app.device.HRVRRIntervalDevice; + +/** + * Copyright (c) 2017 + * Created by Thomas Czogalik on 23.04.2017 + */ + +public interface IMeasuringView { + Activity getParentActivity(); + + void addDeviceListeners(); + + HRVRRIntervalDevice getHrvRrIntervalDevice(); + + void setHrvRrIntervalDevice(HRVRRIntervalDevice hrvRrIntervalDevice); + + void toggleDeviceMenuButton(boolean toggle); + + void showCancelDialog(); + + boolean isAnimationRunning(); + + void startMeasurementActivity(); + + void makeToast(int messageId); + + void showSnackbar(String s); + + void resetProgress(); + + void setConnectionButtonClickable(boolean clickable); + + void stopMeasuring(); +} diff --git a/app/src/main/java/hrv/band/app/ui/view/fragment/MeasuringFragment.java b/app/src/main/java/hrv/band/app/ui/view/fragment/MeasuringFragment.java index 0d1ae47..8ed8745 100644 --- a/app/src/main/java/hrv/band/app/ui/view/fragment/MeasuringFragment.java +++ b/app/src/main/java/hrv/band/app/ui/view/fragment/MeasuringFragment.java @@ -1,15 +1,12 @@ package hrv.band.app.ui.view.fragment; -import android.animation.Animator; import android.animation.ObjectAnimator; import android.app.Activity; import android.app.AlertDialog; import android.content.Intent; -import android.content.SharedPreferences; import android.graphics.Point; import android.os.Bundle; import android.os.CountDownTimer; -import android.preference.PreferenceManager; import android.support.design.widget.Snackbar; import android.support.v4.app.Fragment; import android.util.Log; @@ -24,19 +21,19 @@ import android.widget.TextView; import android.widget.Toast; -import org.apache.commons.lang3.ArrayUtils; - import java.util.Date; -import hrv.RRData; import hrv.band.app.R; +import hrv.band.app.device.ConnectionManager; import hrv.band.app.device.HRVDeviceStatus; import hrv.band.app.device.HRVRRDeviceListener; import hrv.band.app.device.HRVRRIntervalDevice; -import hrv.band.app.device.antplus.AntPlusRRDataDevice; -import hrv.band.app.device.msband.MSBandRRIntervalDevice; -import hrv.band.app.model.Measurement; +import hrv.band.app.ui.presenter.IMeasuringPresenter; +import hrv.band.app.ui.presenter.MeasuringPresenter; import hrv.band.app.ui.view.activity.SavableMeasurementActivity; +import hrv.band.app.ui.view.fragment.measuring.listener.ConnectionClickListener; +import hrv.band.app.ui.view.fragment.measuring.listener.MeasurementClickListener; +import hrv.band.app.ui.view.fragment.measuring.listener.ProgressBarAnimatorListener; import hrv.calc.continous.HRVContinousHeartRate; import hrv.calc.continous.HRVParameterChangedListener; import hrv.calc.continous.HRVRRIntervalEvent; @@ -49,20 +46,12 @@ *

* Fragment allowing user to start measurement. */ -public class MeasuringFragment extends Fragment implements HRVRRDeviceListener, HRVRRIntervalListener, HRVParameterChangedListener { +public class MeasuringFragment extends Fragment implements HRVRRDeviceListener, HRVRRIntervalListener, HRVParameterChangedListener, IMeasuringView { /** * Key value for the calculated hrv parameter. **/ private static final String HRV_PARAMETER_ID = "HRV_PARAMETER"; - /** - * Key value for the selected measure device. - **/ - private static final String SELECTED_DEVICE_ID = "selected_device_id"; - /** - * The shared preferences. - **/ - private SharedPreferences sharedPreferences; /** * Device to measure rr interval. **/ @@ -95,6 +84,7 @@ public class MeasuringFragment extends Fragment implements HRVRRDeviceListener, * continously calculates the pulse **/ private HRVContinousHeartRate pulseCalculator; + private com.github.clans.fab.FloatingActionMenu menuDown; /** * Button to connect with the ms band. **/ @@ -116,6 +106,9 @@ public class MeasuringFragment extends Fragment implements HRVRRDeviceListener, **/ private View view; + private IMeasuringPresenter presenter; + + /** * Returns a new instance of this fragment. * @@ -169,6 +162,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, View rootView = inflater.inflate(R.layout.main_fragment_measure, container, false); view = rootView.findViewById(R.id.measure_fragment); + presenter = new MeasuringPresenter(this); + ConnectionManager connectionManager = new ConnectionManager(getActivity()); + rrStatus = (TextView) rootView.findViewById(R.id.rrStatus); pulse = (TextView) rootView.findViewById(R.id.pulseValue); txtStatus = (TextView) rootView.findViewById(R.id.measure_status); @@ -176,34 +172,37 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar); + menuDown = (com.github.clans.fab.FloatingActionMenu) getActivity().findViewById(R.id.menu_down); connectToBandFAB = (com.github.clans.fab.FloatingActionButton) getActivity().findViewById(R.id.connect_band_float_button); connectToAntPlusFAB = (com.github.clans.fab.FloatingActionButton) getActivity().findViewById(R.id.connect_antplus_float_button); disconnectDevices = (com.github.clans.fab.FloatingActionButton) getActivity().findViewById(R.id.disconnect_devices); - sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext()); - txtMeasureTime.setText(String.valueOf(getDuration() / 1000)); + txtMeasureTime.setText(String.valueOf(presenter.getDuration() / 1000)); pulseCalculator = new HRVContinousHeartRate(10); pulseCalculator.addHRVParameterChangedListener(this); - hrvRRIntervalDevice = getDevice(DeviceID.values()[sharedPreferences.getInt(SELECTED_DEVICE_ID, 0)]); + + hrvRRIntervalDevice = connectionManager.getDevice(); if (hrvRRIntervalDevice != null) { - addDeviceListeners(this); + addDeviceListeners(); } MeasurementClickListener clickListener = new MeasurementClickListener(this); progressBar.setOnClickListener(clickListener); + + ConnectionClickListener connectClickListener = new ConnectionClickListener(connectionManager, this); + if (connectToBandFAB != null) { - connectToBandFAB.setOnClickListener(clickListener); + connectToBandFAB.setOnClickListener(connectClickListener); } if (connectToAntPlusFAB != null) { - connectToAntPlusFAB.setOnClickListener(clickListener); + connectToAntPlusFAB.setOnClickListener(connectClickListener); } if (disconnectDevices != null) { - disconnectDevices.setOnClickListener(clickListener); + disconnectDevices.setOnClickListener(connectClickListener); } - setProgressBarSize(); initAnimation(); @@ -215,7 +214,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, * Starts a countdown that shows how long the measurement will go on. */ private void startCountdown() { - countDownTimer = new CountDownTimer(getDuration(), 1000) { + countDownTimer = new CountDownTimer(presenter.getDuration(), 1000) { @Override public void onTick(long millisUntilFinished) { txtMeasureTime.setText(String.valueOf(millisUntilFinished / 1000)); @@ -223,47 +222,54 @@ public void onTick(long millisUntilFinished) { @Override public void onFinish() { - txtMeasureTime.setText(String.valueOf(getDuration())); + txtMeasureTime.setText(String.valueOf(presenter.getDuration())); } }.start(); } - /** - * Returns the measurement duration in ms. - * - * @return measurement duration in ms. - */ - private int getDuration() { - String durationPrefVal = sharedPreferences.getString("recording_length", "90"); - return Integer.parseInt(durationPrefVal) * 1000; - } - /** * Adds listeners to the measurement device. - * - * @param measuringFragment the measure fragment. */ - private void addDeviceListeners(MeasuringFragment measuringFragment) { - hrvRRIntervalDevice.addDeviceListener(measuringFragment); - hrvRRIntervalDevice.addRRIntervalListener(measuringFragment); + @Override + public void addDeviceListeners() { + hrvRRIntervalDevice.addDeviceListener(this); + hrvRRIntervalDevice.addRRIntervalListener(this); hrvRRIntervalDevice.addRRIntervalListener(pulseCalculator); } - /** - * Returns the measurement device from the given id. - * - * @param id the device id from the actual measurement device. - * @return the measurement device from the given id. - */ - private HRVRRIntervalDevice getDevice(DeviceID id) { - switch (id) { - case MSBAND: - return new MSBandRRIntervalDevice(getActivity()); - case ANT: - return new AntPlusRRDataDevice(getContext(), getActivity()); - default: - return null; - } + @Override + public HRVRRIntervalDevice getHrvRrIntervalDevice() { + return hrvRRIntervalDevice; + } + + @Override + public void setHrvRrIntervalDevice(HRVRRIntervalDevice hrvRRIntervalDevice) { + this.hrvRRIntervalDevice = hrvRRIntervalDevice; + } + + @Override + public void toggleDeviceMenuButton(boolean toggle) { + menuDown.toggle(toggle); + } + + @Override + public void showCancelDialog() { + CancelMeasuringDialogFragment.newInstance().show(getActivity().getFragmentManager(), "dialog"); + } + + @Override + public boolean isAnimationRunning() { + return animation.isRunning(); + } + + @Override + public void makeToast(int messageId) { + Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.msg_select_device), Toast.LENGTH_SHORT).show(); + } + + @Override + public void showSnackbar(String message) { + showSnackbar(view, message); } @Override @@ -315,12 +321,13 @@ private void setStatusTextSize(int width) { private void initAnimation() { animation = ObjectAnimator.ofInt(progressBar, "progress", 0, 1000); animation.setInterpolator(new LinearInterpolator()); - animation.addListener(new ProgressBarAnimatorListener()); + animation.addListener(new ProgressBarAnimatorListener(this)); } /** * Stops the measuring of the device and resets the ui. */ + @Override public void stopMeasuring() { if (hrvRRIntervalDevice != null && animation != null) { hrvRRIntervalDevice.stopMeasuring(); @@ -333,7 +340,8 @@ public void stopMeasuring() { /** * Resets the ui. */ - private void resetProgress() { + @Override + public void resetProgress() { progressBar.setProgress(progressBar.getMax()); setConnectionButtonClickable(true); @@ -346,7 +354,7 @@ private void resetProgress() { if (countDownTimer != null) { countDownTimer.cancel(); } - updateTextView(getActivity(), txtMeasureTime, String.valueOf(getDuration() / 1000)); + updateTextView(getActivity(), txtMeasureTime, String.valueOf(presenter.getDuration() / 1000)); getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } @@ -356,7 +364,8 @@ private void resetProgress() { * * @param clickable true if buttons should be clickable, false otherwise. */ - private void setConnectionButtonClickable(boolean clickable) { + @Override + public void setConnectionButtonClickable(boolean clickable) { connectToAntPlusFAB.setClickable(clickable); connectToBandFAB.setClickable(clickable); disconnectDevices.setClickable(clickable); @@ -371,7 +380,7 @@ public void deviceStartedMeasurement() { @Override public void run() { if (animation != null) { - animation.setDuration(getDuration()); + animation.setDuration(presenter.getDuration()); animation.start(); startCountdown(); getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); @@ -411,187 +420,28 @@ public void parameterChanged(HRVParameter eventArgs) { updateTextView(getActivity(), pulse, format); } - /** - * Possible devices the user can select. - **/ - private enum DeviceID { - NONE, MSBAND, ANT + @Override + public Activity getParentActivity() { + return getActivity(); } - /** - * Animator Listener for the progress bar. - */ - private class ProgressBarAnimatorListener implements Animator.AnimatorListener { - - @Override - public void onAnimationStart(Animator a) { - setConnectionButtonClickable(false); - } - - @Override - public void onAnimationEnd(Animator animation) { - if (hrvRRIntervalDevice == null) { - showSnackbar(view, "This should not happen..."); - } - hrvRRIntervalDevice.stopMeasuring(); - - double[] rrIntervals = ArrayUtils.toPrimitive(hrvRRIntervalDevice.getRRIntervals().toArray(new Double[0])); - - try { - Intent intent = new Intent(getContext(), SavableMeasurementActivity.class); - intent.putExtra(HRV_PARAMETER_ID, createMeasurement(rrIntervals, new Date())); - startActivity(intent); - } catch (IllegalArgumentException e) { - Log.e(e.getClass().getName(), "IllegalArgumentException", e); - new AlertDialog.Builder(getContext()) - .setTitle(R.string.error) - .setMessage(R.string.error_defective_rr_data) - .setPositiveButton(android.R.string.ok, null) - .show(); - } - - hrvRRIntervalDevice.clearRRIntervals(); - resetProgress(); - } - - @Override - public void onAnimationCancel(Animator animation) { - animation.removeAllListeners(); - } - - @Override - public void onAnimationRepeat(Animator animation) { - //is not used at the moment - } - - /** - * Calculates hrv parameter from given rr interval. - * - * @param rrInterval measured rr interval. - * @param time time the measurement was created. - * @return calculated hrv parameter from given rr interval. - */ - private Measurement createMeasurement(double[] rrInterval, Date time) { - //start calculation - RRData.createFromRRInterval(rrInterval, units.TimeUnit.SECOND); - - Measurement.MeasurementBuilder measurementBuilder = Measurement.from(time, rrInterval); - return measurementBuilder.build(); + @Override + public void startMeasurementActivity() { + try { + Intent intent = new Intent(getContext(), SavableMeasurementActivity.class); + intent.putExtra(MeasuringFragment.HRV_PARAMETER_ID, presenter.createMeasurement(hrvRRIntervalDevice.getRRIntervals(), new Date())); + startActivity(intent); + } catch (IllegalArgumentException e) { + Log.e(e.getClass().getName(), "IllegalArgumentException", e); + showAlertDialog(R.string.error, R.string.error_defective_rr_data); } } - /** - * Click listener handling the clicks in this fragment. - */ - private class MeasurementClickListener implements View.OnClickListener { - - /** - * The measuring fragment. - **/ - private final MeasuringFragment measuringFragment; - /** - * The activity holding the fragment. - **/ - private final Activity activity; - /** - * The connection button containing the other buttons to (dis)connect the devices. - **/ - private final com.github.clans.fab.FloatingActionMenu menuDown; - - MeasurementClickListener(MeasuringFragment measuringFragment) { - this.measuringFragment = measuringFragment; - this.activity = measuringFragment.getActivity(); - menuDown = (com.github.clans.fab.FloatingActionMenu) activity.findViewById(R.id.menu_down); - } - - @Override - public void onClick(View view) { - switch (view.getId()) { - case R.id.progressBar: - startMeasurement(); - break; - case R.id.connect_antplus_float_button: - connectToAnt(); - break; - case R.id.connect_band_float_button: - connectToMSBand(); - break; - case R.id.disconnect_devices: - disconnectDevices(); - break; - default: - break; - } - } - - /** - * Starts a measurement or opens a cancel dialog if measurement already in progress. - */ - private void startMeasurement() { - if (animation.isRunning()) { - CancelMeasuringDialogFragment.newInstance().show(activity.getFragmentManager(), "dialog"); - } else { - if (hrvRRIntervalDevice != null) { - hrvRRIntervalDevice.tryStartRRIntervalMeasuring(); - } else { - Toast.makeText(activity, activity.getResources().getString(R.string.msg_select_device), Toast.LENGTH_SHORT).show(); - menuDown.open(true); - } - } - } - - /** - * Connects to ms band. - */ - private void connectToMSBand() { - setDevice(DeviceID.MSBAND); - - hrvRRIntervalDevice = new MSBandRRIntervalDevice(activity); - initDevice(); - } - - /** - * Connects to ant+ device. - */ - private void connectToAnt() { - setDevice(DeviceID.ANT); - - hrvRRIntervalDevice = new AntPlusRRDataDevice(activity.getApplicationContext(), activity); - initDevice(); - } - - /** - * Disconnects connected device. - */ - private void disconnectDevices() { - setDevice(DeviceID.NONE); - if (hrvRRIntervalDevice != null) { - hrvRRIntervalDevice.notifyDeviceStatusChanged(HRVDeviceStatus.DISCONNECTED); - hrvRRIntervalDevice = null; - } - menuDown.toggle(true); - - Toast.makeText(activity, activity.getResources().getString(R.string.msg_disconnecting), Toast.LENGTH_SHORT).show(); - } - - /** - * Initialize selected device. - */ - private void initDevice() { - addDeviceListeners(measuringFragment); - hrvRRIntervalDevice.connect(); - menuDown.toggle(true); - } - - /** - * Sets the selected device in preferences. - * - * @param device the device id. - */ - private void setDevice(DeviceID device) { - SharedPreferences.Editor prefsEditor = sharedPreferences.edit(); - prefsEditor.putInt(SELECTED_DEVICE_ID, device.ordinal()); - prefsEditor.apply(); - } + private void showAlertDialog(int title, int message) { + new AlertDialog.Builder(getContext()) + .setTitle(title) + .setMessage(message) + .setPositiveButton(android.R.string.ok, null) + .show(); } } diff --git a/app/src/main/java/hrv/band/app/ui/view/fragment/measuring/listener/ConnectionClickListener.java b/app/src/main/java/hrv/band/app/ui/view/fragment/measuring/listener/ConnectionClickListener.java new file mode 100644 index 0000000..2d41778 --- /dev/null +++ b/app/src/main/java/hrv/band/app/ui/view/fragment/measuring/listener/ConnectionClickListener.java @@ -0,0 +1,45 @@ +package hrv.band.app.ui.view.fragment.measuring.listener; + +import android.view.View; + +import hrv.band.app.R; +import hrv.band.app.device.ConnectionManager; +import hrv.band.app.ui.view.fragment.IMeasuringView; + +/** + * Copyright (c) 2017 + * Created by Thomas Czogalik on 23.04.2017 + * + * Click listener handling the clicks in this fragment. + */ +public class ConnectionClickListener implements View.OnClickListener { + + private ConnectionManager connectionManager; + private IMeasuringView measuringView; + + public ConnectionClickListener(ConnectionManager connectionManager, IMeasuringView measuringView) { + this.connectionManager = connectionManager; + this.measuringView = measuringView; + } + + @Override + public void onClick(View view) { + switch (view.getId()) { + case R.id.connect_antplus_float_button: + measuringView.setHrvRrIntervalDevice(connectionManager.connectToAnt()); + measuringView.addDeviceListeners(); + break; + case R.id.connect_band_float_button: + measuringView.setHrvRrIntervalDevice(connectionManager.connectToMSBand()); + measuringView.addDeviceListeners(); + break; + case R.id.disconnect_devices: + measuringView.setHrvRrIntervalDevice(connectionManager.disconnectDevices(measuringView.getHrvRrIntervalDevice())); + measuringView.makeToast(R.string.msg_disconnecting); + break; + default: + break; + } + measuringView.toggleDeviceMenuButton(true); + } +} diff --git a/app/src/main/java/hrv/band/app/ui/view/fragment/measuring/listener/MeasurementClickListener.java b/app/src/main/java/hrv/band/app/ui/view/fragment/measuring/listener/MeasurementClickListener.java new file mode 100644 index 0000000..4abf177 --- /dev/null +++ b/app/src/main/java/hrv/band/app/ui/view/fragment/measuring/listener/MeasurementClickListener.java @@ -0,0 +1,42 @@ +package hrv.band.app.ui.view.fragment.measuring.listener; + +import android.view.View; + +import hrv.band.app.R; +import hrv.band.app.device.HRVRRIntervalDevice; +import hrv.band.app.ui.view.fragment.IMeasuringView; + +/** + * Copyright (c) 2017 + * Created by Thomas Czogalik on 23.04.2017 + * + * Click listener handling the clicks in this fragment. + */ +public class MeasurementClickListener implements View.OnClickListener { + + private IMeasuringView measuringView; + + public MeasurementClickListener(IMeasuringView measuringView) { + this.measuringView = measuringView; + } + + @Override + public void onClick(View view) { + if (view.getId() == R.id.progressBar) { + startMeasurement(); + } + } + private void startMeasurement() { + if (measuringView.isAnimationRunning()) { + measuringView.showCancelDialog(); + } else { + final HRVRRIntervalDevice hrvRrIntervalDevice = measuringView.getHrvRrIntervalDevice(); + if (hrvRrIntervalDevice != null) { + hrvRrIntervalDevice.tryStartRRIntervalMeasuring(); + } else { + measuringView.makeToast(R.string.msg_select_device); + measuringView.toggleDeviceMenuButton(true); + } + } + } +} diff --git a/app/src/main/java/hrv/band/app/ui/view/fragment/measuring/listener/ProgressBarAnimatorListener.java b/app/src/main/java/hrv/band/app/ui/view/fragment/measuring/listener/ProgressBarAnimatorListener.java new file mode 100644 index 0000000..21f6c1a --- /dev/null +++ b/app/src/main/java/hrv/band/app/ui/view/fragment/measuring/listener/ProgressBarAnimatorListener.java @@ -0,0 +1,52 @@ +package hrv.band.app.ui.view.fragment.measuring.listener; + +import android.animation.Animator; + +import hrv.band.app.device.HRVRRIntervalDevice; +import hrv.band.app.ui.view.fragment.IMeasuringView; + +/** + * Copyright (c) 2017 + * Created by Thomas Czogalik on 23.04.2017 + *

+ * Animator Listener for the progress bar. + */ +public class ProgressBarAnimatorListener implements Animator.AnimatorListener { + + private IMeasuringView measuringView; + + public ProgressBarAnimatorListener(IMeasuringView measuringView) { + this.measuringView = measuringView; + } + + @Override + public void onAnimationStart(Animator a) { + measuringView.setConnectionButtonClickable(false); + } + + @Override + public void onAnimationEnd(Animator animation) { + final HRVRRIntervalDevice hrvRrIntervalDevice = measuringView.getHrvRrIntervalDevice(); + if (hrvRrIntervalDevice == null) { + measuringView.showSnackbar("This should not happen..."); + return; + } + hrvRrIntervalDevice.stopMeasuring(); + + measuringView.startMeasurementActivity(); + + hrvRrIntervalDevice.clearRRIntervals(); + measuringView.resetProgress(); + } + + + @Override + public void onAnimationCancel(Animator animation) { + animation.removeAllListeners(); + } + + @Override + public void onAnimationRepeat(Animator animation) { + //is not used at the moment + } +} diff --git a/app/src/main/java/hrv/band/app/view/activity/AbstractHRVActivity.java b/app/src/main/java/hrv/band/app/view/activity/AbstractHRVActivity.java deleted file mode 100644 index 6be4440..0000000 --- a/app/src/main/java/hrv/band/app/view/activity/AbstractHRVActivity.java +++ /dev/null @@ -1,121 +0,0 @@ -package hrv.band.app.view.activity; - -import android.os.Bundle; -import android.support.design.widget.TabLayout; -import android.support.v4.app.Fragment; -import android.support.v4.view.ViewPager; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; - -import java.util.ArrayList; -import java.util.List; - -import hrv.band.app.control.Measurement; -import hrv.band.app.R; -import hrv.band.app.view.adapter.SectionPagerAdapter; -import hrv.band.app.view.fragment.MeasuredRRFragment; -import hrv.band.app.view.fragment.MeasuredValueFragment; -import hrv.band.app.view.presenter.HRVPresenter; -import hrv.band.app.view.presenter.IHRVPresenter; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 19.01.2017 - * - * This abstract Activity holds the fragments to show a specific HRV value. - */ -public abstract class AbstractHRVActivity extends AppCompatActivity { - /** The Fragments this Activity holds. **/ - private List fragments; - - protected IHRVPresenter presenter; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(); - - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); - - setSupportActionBar(toolbar); - // add back arrow to toolbar - if (getSupportActionBar() != null){ - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setDisplayShowHomeEnabled(true); - } - - presenter = new HRVPresenter((Measurement) getIntent().getParcelableExtra(MainActivity.HRV_PARAMETER_ID)); - - createFragments(); - - setViewPager(); - } - - @Override - public abstract void onBackPressed(); - - /** - * Sets the ViewPager of this Activity. - */ - private void setViewPager() { - ViewPager mViewPager = (ViewPager) findViewById(getViewPagerID()); - SectionPagerAdapter sectionsPagerAdapter = new SectionPagerAdapter(getSupportFragmentManager(), fragments, getPageTitles()); - mViewPager.setAdapter(sectionsPagerAdapter); - - TabLayout tabLayout = (TabLayout) findViewById(getTabID()); - tabLayout.setupWithViewPager(mViewPager); - } - - /** - * Returns the page titles of the fragments. - * @return the page titles of the fragments. - */ - private String[] getPageTitles() { - return new String[] { - getResources().getString(R.string.hrv_activity_tab_value), - getResources().getString(R.string.hrv_activity_tab_rr), - getResources().getString(R.string.hrv_activity_tab_details) - }; - } - - /** - * Sets the contentView of this Activity. - */ - private void setContentView() { - setContentView(getContentViewId()); - } - - /** - * Adds Fragments to this Activity. - */ - private void createFragments() { - fragments = new ArrayList<>(); - fragments.add(MeasuredValueFragment.newInstance(presenter.getMeasurement())); - fragments.add(MeasuredRRFragment.newInstance(presenter.getMeasurement())); - addDetailsFragment(fragments); - } - - /** - * Returns the id of the layout of this activity. - * @return the id of the layout of this activity. - */ - protected abstract int getContentViewId(); - - /** - * Returns the id of the viewPager of this activity. - * @return the id of the viewPager of this activity. - */ - protected abstract int getViewPagerID(); - - /** - * Returns the id of the tabLayout of this activity. - * @return the id of the tabLayout of this activity. - */ - protected abstract int getTabID(); - - /** - * Adds the Fragment to show or set the HRV value details. - * @param fragments list of fragments of this activity. - */ - protected abstract void addDetailsFragment(List fragments); -} diff --git a/app/src/main/java/hrv/band/app/view/activity/HRVMeasurementActivity.java b/app/src/main/java/hrv/band/app/view/activity/HRVMeasurementActivity.java deleted file mode 100644 index fa75574..0000000 --- a/app/src/main/java/hrv/band/app/view/activity/HRVMeasurementActivity.java +++ /dev/null @@ -1,120 +0,0 @@ -package hrv.band.app.view.activity; - -import android.support.v4.app.Fragment; -import android.view.Menu; -import android.view.MenuItem; -import android.widget.Toast; - -import java.util.List; - -import hrv.band.app.R; -import hrv.band.app.view.fragment.IMeasuredDetails; -import hrv.band.app.view.fragment.MeasuredDetailsEditFragment; -import hrv.band.app.view.fragment.TextDialogFragment; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 19.01.2017 - * - * This Activity holds the Fragments which shows the actual HRV Measurement. - */ -public class HRVMeasurementActivity extends AbstractHRVActivity implements ISavableMeasurementView { - private IMeasuredDetails measuredDetailsEditFragment; - - @Override - protected int getContentViewId() { - return R.layout.activity_hrv_measurement; - } - - @Override - protected int getViewPagerID() { - return R.id.measure_details_viewpager; - } - - @Override - protected int getTabID() { - return R.id.measure_details_tabs; - } - - @Override - protected void addDetailsFragment(List fragments) { - measuredDetailsEditFragment = MeasuredDetailsEditFragment.newInstance(); - fragments.add(measuredDetailsEditFragment.getFragment()); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.menu_hrv_measurement, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - onBackPressed(); - return true; - /** Saves the measurement. **/ - case R.id.menu_ic_save: - saveMeasurement(); - return true; - default: - return super.onOptionsItemSelected(item); - } - } - - /** - * Saves the actual measured and calculated HRV parameter. - */ - private void saveMeasurement() { - presenter.saveMeasurement(getApplicationContext(), measuredDetailsEditFragment); - Toast.makeText(this, R.string.common_saved, Toast.LENGTH_SHORT).show(); - finish(); - } - - @Override - public void onBackPressed() { - CancelMeasurementFragment.newInstance().show(getSupportFragmentManager(), "cancel"); - } - - /** - * Dialog which asks the user if he wants to save the measurement. - */ - public static class CancelMeasurementFragment extends TextDialogFragment { - - public static TextDialogFragment newInstance() { - return new CancelMeasurementFragment(); - } - - @Override - public void positiveButton() { - getActivity().finish(); - } - - @Override - public void negativeButton() { - CancelMeasurementFragment.this.getDialog().cancel(); - } - - @Override - public String getDialogTitle() { - return getResources().getString(R.string.hrv_measurement_cancel_title); - } - - @Override - public String getDialogDescription() { - return getResources().getString(R.string.hrv_measurement_cancel_desc); - } - - @Override - public int getDialogPositiveLabel() { - return R.string.common_yes; - } - - @Override - public int getDialogNegativeLabel() { - return R.string.common_no; - } - } -} diff --git a/app/src/main/java/hrv/band/app/view/activity/HRVValueActivity.java b/app/src/main/java/hrv/band/app/view/activity/HRVValueActivity.java deleted file mode 100644 index 25fe73e..0000000 --- a/app/src/main/java/hrv/band/app/view/activity/HRVValueActivity.java +++ /dev/null @@ -1,76 +0,0 @@ -package hrv.band.app.view.activity; - -import android.support.v4.app.Fragment; -import android.view.Menu; -import android.view.MenuItem; - -import java.util.List; - -import hrv.band.app.R; -import hrv.band.app.view.fragment.MeasuredDetailsFragment; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 19.01.2017 - * - * This Activity holds the Fragments which are showing past HRV Measurements. - */ -public class HRVValueActivity extends AbstractHRVActivity { - - @Override - protected int getContentViewId() { - return R.layout.activity_hrv_value; - } - - @Override - protected int getViewPagerID() { - return R.id.hrv_viewpager; - } - - @Override - protected int getTabID() { - return R.id.hrv_tabs; - } - - @Override - protected void addDetailsFragment(List fragments) { - fragments.add(MeasuredDetailsFragment.newInstance(presenter.getMeasurement())); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.menu_hrv_value, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - onBackPressed(); - return true; - case R.id.menu_ic_delete: - deleteMeasurement(); - return true; - default: - return super.onOptionsItemSelected(item); - } - } - - - /** - * Deletes the actual parameter. - */ - private void deleteMeasurement() { - presenter.deleteMeasurement(getApplicationContext()); - setResult(HistoryActivity.RESULT_DELETED); - this.finish(); - } - - @Override - public void onBackPressed() { - finish(); - } - -} diff --git a/app/src/main/java/hrv/band/app/view/activity/HistoryActivity.java b/app/src/main/java/hrv/band/app/view/activity/HistoryActivity.java deleted file mode 100644 index 69fa6a6..0000000 --- a/app/src/main/java/hrv/band/app/view/activity/HistoryActivity.java +++ /dev/null @@ -1,196 +0,0 @@ -package hrv.band.app.view.activity; - -import android.app.DatePickerDialog; -import android.content.Context; -import android.os.Bundle; -import android.support.design.widget.TabLayout; -import android.support.v4.app.Fragment; -import android.support.v4.view.ViewPager; -import android.support.v7.app.ActionBar; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; -import android.view.Menu; -import android.view.MenuItem; -import android.widget.DatePicker; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; - -import hrv.band.app.R; -import hrv.band.app.control.Measurement; -import hrv.band.app.view.adapter.HRVValue; -import hrv.band.app.view.adapter.SectionPagerAdapter; -import hrv.band.app.view.control.chart.AbstractChartDrawStrategy; -import hrv.band.app.view.control.parameter.AbstractParameterLoadStrategy; -import hrv.band.app.view.control.chart.ChartDrawDayStrategy; -import hrv.band.app.view.control.chart.ChartDrawMonthStrategy; -import hrv.band.app.view.control.chart.ChartDrawWeekStrategy; -import hrv.band.app.view.control.IHistoryView; -import hrv.band.app.view.control.parameter.ParameterLoadDayStrategy; -import hrv.band.app.view.control.parameter.ParameterLoadMonthStrategy; -import hrv.band.app.view.control.parameter.ParameterLoadWeekStrategy; -import hrv.band.app.view.fragment.CalenderPickerFragment; -import hrv.band.app.view.fragment.OverviewFragment; -import hrv.band.app.view.fragment.HistoryFragment; -import hrv.band.app.view.presenter.HistoryPresenter; -import hrv.band.app.view.presenter.IHistoryPresenter; -import lecho.lib.hellocharts.view.ColumnChartView; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 19.01.2017 - *

- * This Activity holds the fragments which each shows a HRV value. - */ -public class HistoryActivity extends AppCompatActivity - implements DatePickerDialog.OnDateSetListener, IHistoryView { - - /** - * Code which indicates that a HRV value was deleted. - **/ - public static final int RESULT_DELETED = 42; - /** - * The Fragments this Activity holds. - **/ - private List fragments; - private SectionPagerAdapter sectionsPagerAdapter; - /** - * Parameters to show in this activity. - **/ - private List measurements; - /** - * Date that user wants to show measurements. - **/ - private Date date; - - private IHistoryPresenter presenter; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_statistic); - - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); - - setSupportActionBar(toolbar); - ActionBar actionBar = getSupportActionBar(); - if (actionBar != null) { - actionBar.setDisplayHomeAsUpEnabled(true); - } - - presenter = new HistoryPresenter(this); - - setDrawStrategy(new ChartDrawDayStrategy(), new ParameterLoadDayStrategy()); - - initFragments(); - - //set up viewpager - sectionsPagerAdapter = new SectionPagerAdapter(getSupportFragmentManager(), fragments, presenter.getPageTitles()); - ViewPager mViewPager = (ViewPager) findViewById(R.id.statistic_viewpager); - mViewPager.setAdapter(sectionsPagerAdapter); - - TabLayout tabLayout = (TabLayout) findViewById(R.id.statistic_tabs); - tabLayout.setupWithViewPager(mViewPager); - - HRVValue type = (HRVValue) - getIntent().getSerializableExtra(OverviewFragment.VALUE_TYPE); - - if (type != null) { - mViewPager.setCurrentItem(getTitlePosition(type)); - } - } - - /** - * Creates a fragment for each HRV value. - */ - private void initFragments() { - fragments = new ArrayList<>(); - date = new Date(); - - measurements = presenter.getMeasurements(date); - for (int i = 0; i < HRVValue.values().length; i++) { - fragments.add(HistoryFragment.newInstance(HRVValue.values()[i])); - } - } - - /** - * Returns position of the given HRV value. - * - * @param value the HRV value to get the position. - * @return position of the given HRV value. - */ - private int getTitlePosition(HRVValue value) { - return value.ordinal(); - } - - //What should happen after Date is selected. - @Override - public void onDateSet(DatePicker view, int year, int month, int day) { - Calendar c = Calendar.getInstance(); - c.set(year, month, day, 0, 0, 0); - date = c.getTime(); - updateFragments(); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.menu_statistic, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - - switch (item.getItemId()) { - case R.id.menu_ic_calender: - new CalenderPickerFragment().show(getSupportFragmentManager(), "datePicker"); - return true; - case R.id.menu_day: - setDrawStrategy(new ChartDrawDayStrategy(), new ParameterLoadDayStrategy()); - return true; - case R.id.menu_week: - setDrawStrategy(new ChartDrawWeekStrategy(), new ParameterLoadWeekStrategy()); - return true; - case R.id.menu_month: - setDrawStrategy(new ChartDrawMonthStrategy(date), new ParameterLoadMonthStrategy()); - return true; - default: - return super.onOptionsItemSelected(item); - } - } - - /** - * Sets the chart drawing and parameter selecting strategy. - * - * @param chartStrategy the chart drawing strategy. - * @param parameterStrategy the parameter selecting strategy. - */ - private void setDrawStrategy(AbstractChartDrawStrategy chartStrategy, - AbstractParameterLoadStrategy parameterStrategy) { - presenter.setDrawChartStrategy(chartStrategy); - presenter.setParameterLoadStrategy(parameterStrategy); - updateFragments(); - } - - @Override - public void drawChart(ColumnChartView chart, HRVValue hrvValue, Context context) { - presenter.getChartDrawStrategy().drawChart(measurements, chart, hrvValue, context); - } - - @Override - public List getMeasurements() { - return measurements; - } - - @Override - public void updateFragments() { - if (date == null) { - return; - } - measurements = presenter.getMeasurements(date); - sectionsPagerAdapter.updateFragments(); - } -} diff --git a/app/src/main/java/hrv/band/app/view/activity/ISavableMeasurementView.java b/app/src/main/java/hrv/band/app/view/activity/ISavableMeasurementView.java deleted file mode 100644 index 0f4255f..0000000 --- a/app/src/main/java/hrv/band/app/view/activity/ISavableMeasurementView.java +++ /dev/null @@ -1,8 +0,0 @@ -package hrv.band.app.view.activity; - -/** - * Created by Thomas on 17.04.2017. - */ - -public interface ISavableMeasurementView { -} diff --git a/app/src/main/java/hrv/band/app/view/activity/IWebView.java b/app/src/main/java/hrv/band/app/view/activity/IWebView.java deleted file mode 100644 index 01ff419..0000000 --- a/app/src/main/java/hrv/band/app/view/activity/IWebView.java +++ /dev/null @@ -1,10 +0,0 @@ -package hrv.band.app.view.activity; - -/** - * Copyright (c) 2017 - * Created by Thomas on 14.04.2017. - */ -public interface IWebView { - void loadUrl(String url); - void openBrowserIntent(String url); -} diff --git a/app/src/main/java/hrv/band/app/view/activity/ImprintActivity.java b/app/src/main/java/hrv/band/app/view/activity/ImprintActivity.java deleted file mode 100644 index 86d1813..0000000 --- a/app/src/main/java/hrv/band/app/view/activity/ImprintActivity.java +++ /dev/null @@ -1,101 +0,0 @@ -package hrv.band.app.view.activity; - -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.design.widget.TabLayout; -import android.support.v4.app.Fragment; -import android.support.v4.view.ViewPager; -import android.support.v7.app.ActionBar; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; -import android.view.Menu; -import android.view.MenuItem; - -import java.util.ArrayList; -import java.util.List; - -import hrv.band.app.R; -import hrv.band.app.view.adapter.SectionPagerAdapter; -import hrv.band.app.view.fragment.AboutFragment; -import hrv.band.app.view.fragment.DisclaimerFragment; -import hrv.band.app.view.fragment.FeedbackDialogFragment; -import hrv.band.app.view.fragment.LicenseFragment; -import hrv.band.app.view.fragment.PrivacyFragment; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 19.01.2017 - * - * This Activity holds the fragments to show imprint stuff. - */ -public class ImprintActivity extends AppCompatActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_imprint); - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); - - setSupportActionBar(toolbar); - ActionBar actionBar = getSupportActionBar(); - if (actionBar != null) { - actionBar.setDisplayHomeAsUpEnabled(true); - } - - SectionPagerAdapter mSectionsPagerAdapter = createSectionPagerAdapter(); - setupViewPager(mSectionsPagerAdapter); - } - - @NonNull - private SectionPagerAdapter createSectionPagerAdapter() { - List fragments = createFragments(); - return new SectionPagerAdapter(getSupportFragmentManager(), fragments, getPageTitles()); - } - - @NonNull - private List createFragments() { - List fragments = new ArrayList<>(); - fragments.add(AboutFragment.newInstance()); - fragments.add(LicenseFragment.newInstance()); - fragments.add(DisclaimerFragment.newInstance()); - fragments.add(PrivacyFragment.newInstance()); - return fragments; - } - - private void setupViewPager(SectionPagerAdapter mSectionsPagerAdapter) { - ViewPager mViewPager = (ViewPager) findViewById(R.id.imprint_viewpager); - mViewPager.setAdapter(mSectionsPagerAdapter); - - TabLayout tabLayout = (TabLayout) findViewById(R.id.imprint_tabs); - tabLayout.setupWithViewPager(mViewPager); - } - - /** - * Returns the page titles of the fragments. - * @return the page titles of the fragments. - */ - private String[] getPageTitles() { - return new String[] { - getResources().getString(R.string.tab_about), - getResources().getString(R.string.tab_license), - getResources().getString(R.string.tab_disclaimer), - getResources().getString(R.string.tab_privacy) - }; - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.menu_imprint, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - //opens a feedback dialog - if (item.getItemId() == R.id.menu_ic_feedback) { - FeedbackDialogFragment.newInstance().show(getSupportFragmentManager(), "Feedback"); - return true; - } - return super.onOptionsItemSelected(item); - } -} diff --git a/app/src/main/java/hrv/band/app/view/activity/IntroActivity.java b/app/src/main/java/hrv/band/app/view/activity/IntroActivity.java deleted file mode 100644 index febf18d..0000000 --- a/app/src/main/java/hrv/band/app/view/activity/IntroActivity.java +++ /dev/null @@ -1,135 +0,0 @@ -package hrv.band.app.view.activity; - -import android.content.Context; -import android.content.SharedPreferences; -import android.content.res.Resources; -import android.os.Bundle; -import android.preference.PreferenceManager; -import android.support.v4.app.Fragment; -import android.support.v4.content.ContextCompat; - -import com.github.paolorotolo.appintro.AppIntro; - -import hrv.band.app.R; -import hrv.band.app.view.fragment.IntroFragment; -import hrv.band.app.view.fragment.SampleDataFragment; -import hrv.band.app.view.fragment.TextDialogFragment; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 19.01.2017 - * - * This Activity shows a tutorial to the user. - */ -public class IntroActivity extends AppIntro { - - /** Key value for tutorial if it should start at app start. **/ - public static final String APP_INTRO = "app_intro"; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - Resources resources = getResources(); - - addSlide(IntroFragment.newInstance(resources.getString(R.string.tutorial_welcome_title), resources.getString(R.string.tutorial_welcome_desc), R.drawable.hrv_logo)); - addSlide(IntroFragment.newInstance(resources.getString(R.string.tutorial_connecting_title), resources.getString(R.string.tutorial_connecting_desc), R.drawable.intro_connecting)); - addSlide(IntroFragment.newInstance(resources.getString(R.string.tutorial_measurement_title), resources.getString(R.string.tutorial_measurement_desc), R.drawable.intro_measurement)); - addSlide(IntroFragment.newInstance(resources.getString(R.string.tutorial_saving_title), resources.getString(R.string.tutorial_saving_desc), R.drawable.intro_saving)); - addSlide(IntroFragment.newInstance(resources.getString(R.string.tutorial_personalize_title), resources.getString(R.string.tutorial_personalize_desc), R.drawable.intro_personalize)); - addSlide(IntroFragment.newInstance(resources.getString(R.string.tutorial_values_title), resources.getString(R.string.tutorial_values_desc), R.drawable.intro_values)); - addSlide(IntroFragment.newInstance(resources.getString(R.string.tutorial_monitor_title), resources.getString(R.string.tutorial_monitor_desc), R.drawable.intro_monitor)); - - setBarColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark)); - - // Hide Skip/Done button. - showSkipButton(true); - setProgressButtonEnabled(true); - } - - @Override - public void onBackPressed() { - cancelTutorial(); - } - - @Override - public void onSkipPressed(Fragment currentFragment) { - super.onSkipPressed(currentFragment); - cancelTutorial(); - } - - @Override - public void onDonePressed(Fragment currentFragment) { - super.onDonePressed(currentFragment); - - SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); - if (!sharedPreferences.getBoolean(IntroActivity.APP_INTRO, false)) { - setPreference(getApplicationContext()); - - SampleDataFragment sampleDataFragment = SampleDataFragment.newInstance(true); - sampleDataFragment.show(getFragmentManager(), "dialog"); - } else { - finish(); - } - } - - /** - * Sets the APP_INTRO preference. - * @param context of this activity. - */ - private static void setPreference(Context context) { - SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context); - SharedPreferences.Editor prefsEditor = mPrefs.edit(); - prefsEditor.putBoolean(APP_INTRO, true); - prefsEditor.apply(); - } - - /** - * Opens a cancel dialog. - */ - private void cancelTutorial() { - CancelIntroFragment.newInstance().show(getSupportFragmentManager(), "dialog"); - } - - - /** - * Dialog which asks the user if he wants to cancel the tutorial. - */ - public static class CancelIntroFragment extends TextDialogFragment { - - public static TextDialogFragment newInstance() { - return new CancelIntroFragment(); - } - - @Override - public void positiveButton() { - setPreference(getActivity()); - getActivity().finish(); - } - - @Override - public void negativeButton() { - CancelIntroFragment.this.getDialog().cancel(); - } - - @Override - public String getDialogTitle() { - return getResources().getString(R.string.tutorial_cancel_title); - } - - @Override - public String getDialogDescription() { - return getResources().getString(R.string.tutorial_cancel_desc); - } - - @Override - public int getDialogPositiveLabel() { - return R.string.common_yes; - } - - @Override - public int getDialogNegativeLabel() { - return R.string.common_no; - } - } -} \ No newline at end of file diff --git a/app/src/main/java/hrv/band/app/view/activity/MainActivity.java b/app/src/main/java/hrv/band/app/view/activity/MainActivity.java deleted file mode 100644 index 7bfd155..0000000 --- a/app/src/main/java/hrv/band/app/view/activity/MainActivity.java +++ /dev/null @@ -1,229 +0,0 @@ -package hrv.band.app.view.activity; - -import android.content.ActivityNotFoundException; -import android.content.Intent; -import android.content.SharedPreferences; -import android.content.res.Resources; -import android.net.Uri; -import android.os.Build; -import android.os.Bundle; -import android.preference.PreferenceManager; -import android.support.annotation.NonNull; -import android.support.design.widget.NavigationView; -import android.support.design.widget.TabLayout; -import android.support.v4.app.Fragment; -import android.support.v4.view.GravityCompat; -import android.support.v4.view.ViewPager; -import android.support.v4.widget.DrawerLayout; -import android.support.v7.app.ActionBarDrawerToggle; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; -import android.util.Log; -import android.view.Menu; -import android.view.MenuItem; - -import java.util.ArrayList; -import java.util.List; - -import hrv.band.app.R; -import hrv.band.app.view.adapter.SectionPagerAdapter; -import hrv.band.app.view.fragment.DisclaimerDialogFragment; -import hrv.band.app.view.fragment.FeedbackDialogFragment; -import hrv.band.app.view.fragment.MeasuringFragment; -import hrv.band.app.view.fragment.OverviewFragment; - -import static hrv.band.app.view.util.WebsiteUrls.WEBSITE_PRIVACY_URL; -import static hrv.band.app.view.util.WebsiteUrls.WEBSITE_URL; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 19.01.2017 - * - * This Activity is the main Activity and holds the measurement and overview Fragment. - */ -public class MainActivity extends AppCompatActivity - implements NavigationView.OnNavigationItemSelectedListener { - - public static final String HRV_PARAMETER_ID = "HRV_PARAMETER"; - public static final String HRV_VALUE = "hrv_rr_value"; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - handleDisclaimer(); - - //Needed to set default values - PreferenceManager.setDefaultValues(this, R.xml.settings_fragment, false); - - setContentView(R.layout.navbar_main); - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); - setSupportActionBar(toolbar); - - //NavigationDrawer - DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); - ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( - this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); - assert drawer != null; - drawer.addDrawerListener(toggle); - toggle.syncState(); - - NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); - assert navigationView != null; - - navigationView.setNavigationItemSelectedListener(this); - - //Fragment - List fragments = new ArrayList<>(); - fragments.add(MeasuringFragment.newInstance()); - fragments.add(OverviewFragment.newInstance()); - - SectionPagerAdapter mSectionsPagerAdapter = new SectionPagerAdapter(getSupportFragmentManager(), fragments, getPageTitles()); - - // Set up the ViewPager with the sections adapter. - ViewPager mViewPager = (ViewPager) findViewById(R.id.main_viewpager); - assert mViewPager != null; - - mViewPager.setAdapter(mSectionsPagerAdapter); - - TabLayout tabLayout = (TabLayout) findViewById(R.id.main_tabs); - assert tabLayout != null; - - tabLayout.setupWithViewPager(mViewPager); - } - - /** - * Returns the page titles of the fragments. - * @return the page titles of the fragments. - */ - private String[] getPageTitles() { - return new String[] { - getResources().getString(R.string.common_bold_measure), - getResources().getString(R.string.common_bold_overview) - }; - } - - @Override - public void onBackPressed() { - - //Close the app, if disclaimer has not yet been accepted - int backStackCount = getFragmentManager().getBackStackEntryCount(); - if(backStackCount != 0) { - - SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); - if(!sharedPreferences.getBoolean(DisclaimerDialogFragment.DISCLAIMER_AGREEMENT, false)) { - finish(); - } - } - - //If the Navigation Drawer is opened, a backPressed closes the Navigation Drawer. - DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); - assert drawer != null; - - if (drawer.isDrawerOpen(GravityCompat.START)) { - drawer.closeDrawer(GravityCompat.START); - } else { - super.onBackPressed(); - } - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.main, menu); - return true; - } - - @Override - public boolean onNavigationItemSelected(@NonNull MenuItem item) { - // Handle navigation view item clicks here. - int id = item.getItemId(); - if (id == R.id.menu_help) { - startActivity(new Intent(this, IntroActivity.class)); - } else if (id == R.id.menu_website) { - Intent webIntent = new Intent(this, WebActivity.class); - webIntent.putExtra(WebActivity.WEBSITE_URL_ID, WEBSITE_URL); - startActivity(webIntent); - } else if (id == R.id.menu_share) { - openShareIntent(); - } else if (id == R.id.menu_privacy) { - Intent webIntent = new Intent(this, WebActivity.class); - webIntent.putExtra(WebActivity.WEBSITE_URL_ID, WEBSITE_PRIVACY_URL); - startActivity(webIntent); - } else if (id == R.id.menu_feedback) { - FeedbackDialogFragment.newInstance().show(getSupportFragmentManager(), "Feedback"); - } else if (id == R.id.menu_imprint) { - startActivity(new Intent(this, ImprintActivity.class)); - } else if (id == R.id.menu_rate) { - rateApp(); - } else if (id == R.id.menu_Settings) { - startActivity(new Intent(this, SettingsActivity.class)); - } - DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); - assert drawer != null; - - drawer.closeDrawer(GravityCompat.START); - return true; - } - - /** - * Opens play store hence the user can rate the app. - * http://stackoverflow.com/questions/10816757/rate-this-app-link-in-google-play-store-app-on-the-phone - */ - private void rateApp() { - Uri uri = Uri.parse("market://details?id=" + this.getPackageName()); - Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri); - // To count with Play market backstack, After pressing back button, - // to taken back to our application, we need to add following flags to intent. - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | - Intent.FLAG_ACTIVITY_NEW_DOCUMENT | - Intent.FLAG_ACTIVITY_MULTIPLE_TASK); - } - try { - startActivity(goToMarket); - } catch (ActivityNotFoundException e) { - Log.e(e.getClass().getName(), "ActivityNotFoundException", e); - startActivity(new Intent(Intent.ACTION_VIEW, - Uri.parse("http://play.google.com/store/apps/details?id=" + this.getPackageName()))); - } - } - - /** - * Opens dialog which lists all apps the user can share a message with. - */ - private void openShareIntent() { - Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); - sharingIntent.setType("text/plain"); - Resources resources = getResources(); - String shareBody = resources.getString(R.string.share_body); - sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, resources.getString(R.string.share_subject)); - sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody); - startActivity(Intent.createChooser(sharingIntent, resources.getString(R.string.share_via))); - } - - /** - * Stops the measurement. - */ - public void stopMeasuring() { - List fragments = getSupportFragmentManager().getFragments(); - for (Fragment fragment : fragments) { - if (fragment instanceof MeasuringFragment) { - ((MeasuringFragment) fragment).stopMeasuring(); - } - } - } - - /** - * Opens the disclaimer dialog if the app opens the first time. If the user accept the - * disclaimer it will not open again. - */ - private void handleDisclaimer() { - SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); - - if(!sharedPreferences.getBoolean(DisclaimerDialogFragment.DISCLAIMER_AGREEMENT, false)) { - DisclaimerDialogFragment disclaimerDialogFragment = new DisclaimerDialogFragment(); - disclaimerDialogFragment.show(getFragmentManager(), "dialog"); - } - } -} diff --git a/app/src/main/java/hrv/band/app/view/activity/SettingsActivity.java b/app/src/main/java/hrv/band/app/view/activity/SettingsActivity.java deleted file mode 100644 index c04ea4b..0000000 --- a/app/src/main/java/hrv/band/app/view/activity/SettingsActivity.java +++ /dev/null @@ -1,35 +0,0 @@ -package hrv.band.app.view.activity; - -import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; - -import hrv.band.app.R; -import hrv.band.app.view.fragment.SettingsFragment; - -/** - * Copyright (c) 2017 - * Created by Julian Martin on 24.01.2017. - *

- * Preferences are just one single fragment that contain all options grouped by - * category - */ - -public class SettingsActivity extends AppCompatActivity { - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_settings); - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); - setSupportActionBar(toolbar); - - // add back arrow to toolbar - if (getSupportActionBar() != null) { - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setDisplayShowHomeEnabled(true); - } - //Replace Activity with settings fragment content - getFragmentManager().beginTransaction().replace(R.id.content_frame, new SettingsFragment()).commit(); - } -} diff --git a/app/src/main/java/hrv/band/app/view/activity/SplashActivity.java b/app/src/main/java/hrv/band/app/view/activity/SplashActivity.java deleted file mode 100644 index 621e4ba..0000000 --- a/app/src/main/java/hrv/band/app/view/activity/SplashActivity.java +++ /dev/null @@ -1,47 +0,0 @@ -package hrv.band.app.view.activity; - -import android.content.Intent; -import android.os.Bundle; -import android.os.Handler; -import android.support.v7.app.AppCompatActivity; -import android.view.animation.Animation; -import android.view.animation.AnimationUtils; -import android.widget.ImageView; - -import hrv.band.app.R; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 19.01.2017 - * - * This Activity is shown if the app starts. - */ -public class SplashActivity extends AppCompatActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.content_splash); - - animateLogo(); - - final int splashTimeOut = 1000; - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Intent intent = new Intent(SplashActivity.this, MainActivity.class); - startActivity(intent); - finish(); - } - }, splashTimeOut); - } - - /** - * Make sure that the logo fades in. - */ - private void animateLogo() { - ImageView imageView = (ImageView) findViewById(R.id.splash_logo); - Animation startAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_in_animation); - imageView.startAnimation(startAnimation); - } -} \ No newline at end of file diff --git a/app/src/main/java/hrv/band/app/view/activity/WebActivity.java b/app/src/main/java/hrv/band/app/view/activity/WebActivity.java deleted file mode 100644 index d781c01..0000000 --- a/app/src/main/java/hrv/band/app/view/activity/WebActivity.java +++ /dev/null @@ -1,148 +0,0 @@ -package hrv.band.app.view.activity; - -import android.content.Intent; -import android.net.Uri; -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.design.widget.NavigationView; -import android.support.v4.view.GravityCompat; -import android.support.v4.widget.DrawerLayout; -import android.support.v7.app.ActionBarDrawerToggle; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; -import android.view.Menu; -import android.view.MenuItem; -import android.webkit.WebView; - -import hrv.band.app.R; -import hrv.band.app.view.presenter.IWebPresenter; -import hrv.band.app.view.presenter.WebPresenter; - -import static hrv.band.app.view.util.WebsiteUrls.*; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 04.02.2017 - * - * This Activity contains a web view and shows the app website. - */ -public class WebActivity extends AppCompatActivity - implements NavigationView.OnNavigationItemSelectedListener, IWebView { - - public static final String WEBSITE_URL_ID = "website_url_id"; - - private WebView webView; - private IWebPresenter webPresenter; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_web); - - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); - setSupportActionBar(toolbar); - settingUpNavigationBar(toolbar); - - webPresenter = new WebPresenter(this); - - settingUpWebView(); - } - - private void settingUpWebView() { - webView = (WebView) findViewById(R.id.webView); - - String url = getIntent().getStringExtra(WEBSITE_URL_ID); - if (!url.contains(HOST_URL)) { - url = WEBSITE_URL; - } - - loadUrl(url); - webView.setWebViewClient(webPresenter.getWebViewClient()); - } - - private void settingUpNavigationBar(Toolbar toolbar) { - DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); - ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( - this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); - drawer.addDrawerListener(toggle); - toggle.syncState(); - - NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); - navigationView.setNavigationItemSelectedListener(this); - } - - @Override - public void onBackPressed() { - DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); - if (drawer.isDrawerOpen(GravityCompat.START)) { - drawer.closeDrawer(GravityCompat.START); - } else { - navigateBack(); - } - } - - @Override - public boolean onNavigationItemSelected(@NonNull MenuItem item) { - int id = item.getItemId(); - if (id == R.id.web_nav_back) { - finish(); - } else { - webPresenter.loadUrl(id); - } - closeDrawer(); - return true; - } - - private void closeDrawer() { - DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); - drawer.closeDrawer(GravityCompat.START); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.menu_web, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - onBackPressed(); - return true; - - case R.id.web_home: - loadUrl(WEBSITE_URL); - return true; - - case R.id.web_open_in_browser: - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(webView.getUrl()))); - return true; - - default: - return super.onOptionsItemSelected(item); - } - } - - /** - * Navigate back through website and return to called activity if website can't go back. - */ - private void navigateBack() { - if(webView.canGoBack()) { - webView.goBack(); - } else { - finish(); - } - } - - @Override - public void loadUrl(String url) { - webView.loadUrl(url); - } - - @Override - public void openBrowserIntent(String url) { - Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); - webView.getContext().startActivity(intent); - } -} diff --git a/app/src/main/java/hrv/band/app/view/adapter/AbstractCategoryAdapter.java b/app/src/main/java/hrv/band/app/view/adapter/AbstractCategoryAdapter.java deleted file mode 100644 index 79b6cee..0000000 --- a/app/src/main/java/hrv/band/app/view/adapter/AbstractCategoryAdapter.java +++ /dev/null @@ -1,115 +0,0 @@ -package hrv.band.app.view.adapter; - -import android.content.Context; -import android.content.res.Resources; -import android.graphics.drawable.Drawable; -import android.support.v4.content.res.ResourcesCompat; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.BaseAdapter; -import android.widget.ImageView; -import android.widget.TextView; - -import java.util.List; - -import hrv.band.app.R; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 19.01.2017 - * - * Abstract adapter for displaying categories. - */ -public abstract class AbstractCategoryAdapter extends BaseAdapter { - - @Override - public int getCount() { - return getCategories().size(); - } - - @Override - public Object getItem(int i) { - return getCategories().get(i); - } - - @Override - public long getItemId(int i) { - return i; - } - - @Override - public View getView(int i, View convertView, ViewGroup viewGroup) { - - ViewHolder holder; - if (convertView == null) { - LayoutInflater inflater = (LayoutInflater) getContext() - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - convertView = inflater.inflate(R.layout.spinner_category_item, viewGroup, false); - holder = new ViewHolder(); - holder.categoryTxt = (TextView) convertView.findViewById(R.id.category_name); - holder.categoryIcon = (ImageView) convertView.findViewById(R.id.category_icon); - convertView.setTag(holder); - } else { - holder = (ViewHolder) convertView.getTag(); - } - - holder.categoryTxt.setText(getCategories().get(i).getName(getContext().getResources())); - holder.categoryIcon.setImageDrawable(getCategories().get(i).getIcon(getContext().getResources())); - return convertView; - } - - /** - * Returns the context of the activity using this adapter. - * @return the context of the activity using this adapter. - */ - protected abstract Context getContext(); - - /** - * Returns a list containing a tuple of name and icon for each category. - * @return a list containing a tuple of name and icon for each category. - */ - protected abstract List getCategories(); - - - /** - * Represents a Category containing a name and an icon. - */ - class Category { - /** The id of the category name. **/ - private final int name; - /** The id of the category icon. **/ - private final int icon; - - Category(int text, int icon) { - this.name = text; - this.icon = icon; - } - - /** - * Returns the name of a category. - * @param resources the resources to resolve the category name from it's id. - * @return the name of a category. - */ - String getName(Resources resources) { - return resources.getString(name); - } - - /** - * Returns the icon of a category. - * @param resources the resources to resolve the category icon from it's id. - * @return the icon of a category. - */ - Drawable getIcon(Resources resources) { - return ResourcesCompat.getDrawable(resources, icon, null); - } - } - - /** - * The ViewHolder of this adapter. - */ - private static class ViewHolder { - private TextView categoryTxt; - private ImageView categoryIcon; - } -} diff --git a/app/src/main/java/hrv/band/app/view/adapter/FeedbackCategoryAdapter.java b/app/src/main/java/hrv/band/app/view/adapter/FeedbackCategoryAdapter.java deleted file mode 100644 index 3088bd9..0000000 --- a/app/src/main/java/hrv/band/app/view/adapter/FeedbackCategoryAdapter.java +++ /dev/null @@ -1,70 +0,0 @@ -package hrv.band.app.view.adapter; - - -import android.content.Context; -import android.content.res.Resources; - -import java.util.ArrayList; -import java.util.List; - -import hrv.band.app.R; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 19.01.2017 - * - * Adapter for displaying feedback categories. - */ -public class FeedbackCategoryAdapter extends AbstractCategoryAdapter { - - /** The context of the calling activity. **/ - private final Context context; - - public FeedbackCategoryAdapter(Context context) { - this.context = context; - } - - @Override - protected Context getContext() { - return context; - } - - @Override - public List getCategories() { - List categories = new ArrayList<>(); - for (FeedbackCategory category : FeedbackCategory.values()) { - categories.add(new Category(category.text, category.icon)); - } - return categories; - } - - /** - * Enum that represents all possible feedback categories. - */ - public enum FeedbackCategory { - BUG(R.string.feedback_category_bug, R.drawable.ic_bug), - IDEA(R.string.feedback_category_idea, R.drawable.ic_idea), - QUESTION(R.string.feedback_category_question, R.drawable.ic_question) - ; - - /** The id of the category name. **/ - private final int text; - /** The id of the category icon. **/ - private final int icon; - - FeedbackCategory(int text, int icon) { - this.text = text; - this.icon = icon; - } - /** - * Returns the name of a category. - * @param resources the resources to resolve the category name from it's id. - * @return the name of a category. - */ - public String getText(Resources resources) { - return resources.getString(text); - } - } -} - - diff --git a/app/src/main/java/hrv/band/app/view/adapter/HRVValue.java b/app/src/main/java/hrv/band/app/view/adapter/HRVValue.java deleted file mode 100644 index 4d3aff5..0000000 --- a/app/src/main/java/hrv/band/app/view/adapter/HRVValue.java +++ /dev/null @@ -1,49 +0,0 @@ -package hrv.band.app.view.adapter; - -import hrv.calc.parameter.HRVParameterEnum; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 19.01.2017 - * - * This enum holds all available HRV values. - */ -public enum HRVValue { - LFHF("LFHF", "%", HRVParameterEnum.LFHF), - HF("HF", "ms²", HRVParameterEnum.HF), - LF("LF", "ms²", HRVParameterEnum.LF), - SDNN("SDNN", "ms", HRVParameterEnum.SDNN), - SD1("SD1", "ms", HRVParameterEnum.SD1), - SD2("SD2", "ms", HRVParameterEnum.SD2), - RMSSD("RMSSD", "ms", HRVParameterEnum.RMSSD), - BAEVSKY("Baevsky", "", HRVParameterEnum.BAEVSKY) - ; - - /** Name of the value **/ - private final String text; - /** Unit in which the value is described. **/ - private final String unit; - - private final HRVParameterEnum hrvParam; - - HRVValue(final String text, final String unit, final HRVParameterEnum hrvParam) { - this.text = text; - this.unit = unit; - this.hrvParam = hrvParam; - } - - @Override - public String toString() { - return text; - } - - /** - * Returns unit in which the value is described. - * @return unit in which the value is described. - */ - public String getUnit() { - return unit; - } - - public HRVParameterEnum getHRVparam() { return hrvParam; } -} \ No newline at end of file diff --git a/app/src/main/java/hrv/band/app/view/adapter/LicenseAdapter.java b/app/src/main/java/hrv/band/app/view/adapter/LicenseAdapter.java deleted file mode 100644 index 304e414..0000000 --- a/app/src/main/java/hrv/band/app/view/adapter/LicenseAdapter.java +++ /dev/null @@ -1,85 +0,0 @@ -package hrv.band.app.view.adapter; - -import android.content.Context; -import android.content.res.Resources; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.BaseAdapter; -import android.widget.TextView; - -import hrv.band.app.R; -import hrv.band.app.view.fragment.LicenseFragment; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 19.01.2017 - * - * This adapter handel's the licenses in the {@link LicenseFragment}. - */ -public class LicenseAdapter extends BaseAdapter { - - /** Context of Activity holding this adapter. **/ - private final Context context; - /** The titles of one license. **/ - private final String[] titles; - /** The link to the used libary. **/ - private final String[] links; - /** The license text. **/ - private final String[] texts; - - public LicenseAdapter(Context context) { - this.context = context; - Resources resources = context.getResources(); - titles = resources.getStringArray(R.array.license_title_array); - links = resources.getStringArray(R.array.license_link_array); - texts = resources.getStringArray(R.array.license_text_array); - } - - @Override - public View getView(int i, View convertView, ViewGroup viewGroup) { - ViewHolder holder; - if (convertView == null) { - LayoutInflater inflater = (LayoutInflater) context - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - convertView = inflater.inflate(R.layout.license_item, viewGroup, false); - holder = new ViewHolder(); - holder.title = (TextView) convertView.findViewById(R.id.licence_title); - holder.link = (TextView) convertView.findViewById(R.id.licence_link); - holder.text = (TextView) convertView.findViewById(R.id.license_text); - convertView.setTag(holder); - } else { - holder = (ViewHolder) convertView.getTag(); - } - - holder.title.setText(titles[i]); - holder.link.setText(links[i]); - holder.text.setText(texts[i]); - - return convertView; - } - @Override - public Object getItem(int i) { - return titles[i]; - } - - @Override - public long getItemId(int position) { - return position; - } - - @Override - public int getCount() { - return titles.length; - } - - - /** - * The ViewHolder of this adapter. - */ - private static class ViewHolder { - private TextView title; - private TextView link; - private TextView text; - } -} diff --git a/app/src/main/java/hrv/band/app/view/adapter/MeasurementCategoryAdapter.java b/app/src/main/java/hrv/band/app/view/adapter/MeasurementCategoryAdapter.java deleted file mode 100644 index cad0801..0000000 --- a/app/src/main/java/hrv/band/app/view/adapter/MeasurementCategoryAdapter.java +++ /dev/null @@ -1,79 +0,0 @@ -package hrv.band.app.view.adapter; - -import android.content.Context; -import android.content.res.Resources; -import android.graphics.drawable.Drawable; -import android.support.v4.content.res.ResourcesCompat; - -import java.util.ArrayList; -import java.util.List; - -import hrv.band.app.R; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 19.01.2017 - * - * Adapter for displaying measurement categories. - */ -public class MeasurementCategoryAdapter extends AbstractCategoryAdapter { - - /** The context of the calling activity. **/ - private final Context context; - - public MeasurementCategoryAdapter(Context context) { - this.context = context; - } - - @Override - protected Context getContext() { - return context; - } - - @Override - protected List getCategories() { - List categories = new ArrayList<>(); - for (MeasureCategory category : MeasureCategory.values()) { - categories.add(new Category(category.text, category.icon)); - } - return categories; - } - - /** - * Enum that represents all possible measurement categories. - */ - public enum MeasureCategory { - GENERAL(R.string.measure_category_general, R.drawable.ic_general), - RELAXED(R.string.measure_category_relaxed, R.drawable.ic_relaxed), - WORK(R.string.measure_category_work, R.drawable.ic_work), - STRESSED(R.string.measure_category_stressed, R.drawable.ic_stressed), - SPORT(R.string.measure_category_sport, R.drawable.ic_sport) - ; - - /** The id of the category name. **/ - private final int text; - /** The id of the category icon. **/ - private final int icon; - - MeasureCategory(int text, int icon) { - this.text = text; - this.icon = icon; - } - /** - * Returns the name of a category. - * @param resources the resources to resolve the category name from it's id. - * @return the name of a category. - */ - public String getText(Resources resources) { - return resources.getString(text); - } - /** - * Returns the icon of a category. - * @param resources the resources to resolve the category icon from it's id. - * @return the icon of a category. - */ - public Drawable getIcon(Resources resources) { - return ResourcesCompat.getDrawable(resources, icon, null); - } - } -} diff --git a/app/src/main/java/hrv/band/app/view/adapter/OverviewValueAdapter.java b/app/src/main/java/hrv/band/app/view/adapter/OverviewValueAdapter.java deleted file mode 100644 index 46d179f..0000000 --- a/app/src/main/java/hrv/band/app/view/adapter/OverviewValueAdapter.java +++ /dev/null @@ -1,67 +0,0 @@ -package hrv.band.app.view.adapter; - -import android.content.Context; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.BaseAdapter; -import android.widget.TextView; - -import hrv.band.app.R; -import hrv.band.app.view.fragment.OverviewFragment; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 19.01.2017 - * - * Adapter for displaying available HRV values in the {@link OverviewFragment}. - */ -public class OverviewValueAdapter extends BaseAdapter { - - /** The context of the activity holding this adapter. **/ - private final Context context; - - public OverviewValueAdapter(Context context) { - this.context = context; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - ViewHolder holder; - if (convertView == null) { - LayoutInflater inflater = (LayoutInflater) context - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - convertView = inflater.inflate(R.layout.overview_value_item, parent, false); - holder = new ViewHolder(); - holder.firstLine = (TextView) convertView.findViewById(R.id.firstLine); - convertView.setTag(holder); - } else { - holder = (ViewHolder) convertView.getTag(); - } - - holder.firstLine.setText(HRVValue.values()[position].toString()); - return convertView; - } - - @Override - public int getCount() { - return HRVValue.values().length; - } - - @Override - public Object getItem(int i) { - return HRVValue.values()[i]; - } - - @Override - public long getItemId(int position) { - return position; - } - - /** - * The ViewHolder of this adapter. - */ - private static class ViewHolder { - private TextView firstLine; - } -} diff --git a/app/src/main/java/hrv/band/app/view/adapter/SectionPagerAdapter.java b/app/src/main/java/hrv/band/app/view/adapter/SectionPagerAdapter.java deleted file mode 100644 index 3cc6a0a..0000000 --- a/app/src/main/java/hrv/band/app/view/adapter/SectionPagerAdapter.java +++ /dev/null @@ -1,57 +0,0 @@ -package hrv.band.app.view.adapter; - -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentPagerAdapter; - -import java.util.List; -import java.util.Observable; -import java.util.Observer; - -import hrv.band.app.view.fragment.FragmentObserver; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 19.01.2017 - * - * A {@link FragmentPagerAdapter} that returns a fragment corresponding to - * one of the sections/tabs/pages. - */ -public class SectionPagerAdapter extends FragmentPagerAdapter { - - /** The Fragments contained in this adapter. **/ - private final List fragments; - /** The titles of the single Fragments. **/ - private final String[] pageTitles; - - private Observable mObservers = new FragmentObserver(); - - public SectionPagerAdapter(FragmentManager fm, List fragments, String[] pageTitles) { - super(fm); - this.fragments = fragments; - this.pageTitles = pageTitles; - } - - @Override - public Fragment getItem(int position) { - Fragment fragment = fragments.get(position); - if (fragment instanceof Observer) { - mObservers.addObserver((Observer) fragment); - } - return fragment; - } - - @Override - public int getCount() { - return fragments.size(); - } - - @Override - public CharSequence getPageTitle(int position) { - return pageTitles[position]; - } - - public void updateFragments() { - mObservers.notifyObservers(); - } -} diff --git a/app/src/main/java/hrv/band/app/view/adapter/StatisticValueAdapter.java b/app/src/main/java/hrv/band/app/view/adapter/StatisticValueAdapter.java deleted file mode 100644 index 78d7f7c..0000000 --- a/app/src/main/java/hrv/band/app/view/adapter/StatisticValueAdapter.java +++ /dev/null @@ -1,156 +0,0 @@ -package hrv.band.app.view.adapter; - -import android.annotation.TargetApi; -import android.content.Context; -import android.os.Build; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.BaseAdapter; -import android.widget.TextView; - -import java.text.DateFormat; -import java.text.DecimalFormat; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.Date; -import java.util.List; -import java.util.Locale; - -import hrv.HRVLibFacade; -import hrv.RRData; -import hrv.band.app.R; -import hrv.band.app.control.Measurement; -import hrv.band.app.view.fragment.HistoryFragment; -import units.TimeUnit; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 19.01.2017 - * - * This adapter holds the hrv parameters to show in the {@link HistoryFragment}. - */ -public class StatisticValueAdapter extends BaseAdapter { - /** The context of activity holding the adapter. **/ - private final Context context; - /** The hrv values to display in fragment as string. **/ - private List values; - /** The hrv parameters to display. **/ - private List parameters; - /** The hrv type to display in the fragment. **/ - private final HRVValue type; - - public StatisticValueAdapter(Context context, - HRVValue type, List parameters) { - this.context = context; - this.type = type; - this.parameters = parameters; - values = getValues(this.parameters, type); - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - ViewHolder holder; - if (convertView == null) { - LayoutInflater inflater = (LayoutInflater) context - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - convertView = inflater.inflate(R.layout.statistic_value_item, parent, false); - holder = new ViewHolder(); - holder.value = (TextView) convertView.findViewById(R.id.stats_value); - holder.time = (TextView) convertView.findViewById(R.id.stats_time); - holder.category = (TextView) convertView.findViewById(R.id.stats_category); - convertView.setTag(holder); - } else { - holder = (ViewHolder) convertView.getTag(); - } - - holder.time.setText(formatDateTime(parameters.get(position).getTime())); - holder.category.setText(parameters.get(position).getCategory().getText(context.getResources())); - holder.value.setText(values.get(position)); - - return convertView; - } - - /** - * Formats the date and time for the measurement depending on user local. - * @param date the date to format. - * @return the formatted date and time for the measurement depending on user local. - */ - private String formatDateTime(Date date) { - DateFormat dateFormat = new SimpleDateFormat("dd.MM", getCurrentLocale()); - DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(context); - return dateFormat.format(date) + ", " + timeFormat.format(date); - } - - @TargetApi(Build.VERSION_CODES.N) - private Locale getCurrentLocale(){ - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){ - return context.getResources().getConfiguration().getLocales().get(0); - } else{ - //noinspection deprecation - return context.getResources().getConfiguration().locale; - } - } - - /** - * Returns a list containing the value of the given hrv type of all given hrv parameters. - * @param measurements the parameters to extract the value from. - * @param type indicates which value to extract from the given parameters. - * @return a list containing the values of the given hrv type of the given hrv parameters. - */ - private List getValues(List measurements, HRVValue type) { - - List hrvValues = new ArrayList<>(); - - if (measurements != null) { - for (Measurement measurement : measurements) { - HRVLibFacade hrvCalc = new HRVLibFacade(RRData.createFromRRInterval(measurement.getRRIntervals(), TimeUnit.SECOND)); - hrvCalc.setParameters(EnumSet.of(type.getHRVparam())); - - double value = hrvCalc.calculateParameters().get(0).getValue(); - hrvValues.add(new DecimalFormat("#.##").format(value)); - } - } - - return hrvValues; - } - - - /** - * Sets a new set of parameters after something changed (e.g. delete). - * @param parameters new set of parameters - */ - public void setDataset(List parameters) { - this.parameters = parameters; - values = getValues(this.parameters, type); - notifyDataSetChanged(); - } - - @Override - public Object getItem(int i) { - return parameters.get(i); - } - - @Override - public int getCount() { - if (parameters == null) { - return 0; - } - return parameters.size(); - } - - @Override - public long getItemId(int i) { - return i; - } - - /** - * The ViewHolder of this adapter. - */ - private static class ViewHolder { - private TextView value; - private TextView time; - private TextView category; - } -} diff --git a/app/src/main/java/hrv/band/app/view/adapter/ValueAdapter.java b/app/src/main/java/hrv/band/app/view/adapter/ValueAdapter.java deleted file mode 100644 index 61be3e5..0000000 --- a/app/src/main/java/hrv/band/app/view/adapter/ValueAdapter.java +++ /dev/null @@ -1,85 +0,0 @@ -package hrv.band.app.view.adapter; - -import android.content.Context; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.BaseAdapter; -import android.widget.TextView; - -import java.text.DecimalFormat; -import java.util.List; - -import hrv.band.app.R; -import hrv.band.app.view.fragment.MeasuredValueFragment; -import hrv.calc.parameter.HRVParameter; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 19.01.2017 - * - * This adapter holds the hrv parameters to show in the {@link MeasuredValueFragment}. - */ -public class ValueAdapter extends BaseAdapter { - - /** The context of activity holding the adapter. **/ - private final Context context; - /** The hrv parameter to display. **/ - private final List parameters; - - public ValueAdapter(Context context, List parameters) { - this.context = context; - this.parameters = parameters; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - ViewHolder holder; - if (convertView == null) { - LayoutInflater inflater = (LayoutInflater) context - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - convertView = inflater.inflate(R.layout.measure_list_item, parent, false); - holder = new ViewHolder(); - holder.descText = (TextView) convertView.findViewById(R.id.measure_value_desc); - holder.valueText = (TextView) convertView.findViewById(R.id.hrv_value); - holder.unitText = (TextView) convertView.findViewById(R.id.measure_value_unit); - convertView.setTag(holder); - } else { - holder = (ViewHolder) convertView.getTag(); - } - - if (parameters != null) { - HRVParameter param = (HRVParameter)getItem(position); - holder.descText.setText(param.getName()); - holder.valueText.setText(new DecimalFormat("#.##").format(param.getValue())); - holder.unitText.setText(param.getUnit()); - } - - return convertView; - } - - @Override - public Object getItem(int i) { - return parameters.get(i); - } - - @Override - public int getCount() { - return parameters.size(); - } - - @Override - public long getItemId(int i) { - return i; - } - - /** - * The ViewHolder of this adapter. - */ - private static class ViewHolder { - private TextView descText; - private TextView valueText; - private TextView unitText; - } -} - diff --git a/app/src/main/java/hrv/band/app/view/control/IHistoryView.java b/app/src/main/java/hrv/band/app/view/control/IHistoryView.java deleted file mode 100644 index 1c6e8db..0000000 --- a/app/src/main/java/hrv/band/app/view/control/IHistoryView.java +++ /dev/null @@ -1,39 +0,0 @@ -package hrv.band.app.view.control; - -import android.content.Context; - -import java.util.List; - -import hrv.band.app.control.Measurement; -import hrv.band.app.view.activity.HistoryActivity; -import hrv.band.app.view.adapter.HRVValue; -import hrv.band.app.view.fragment.HistoryFragment; -import lecho.lib.hellocharts.view.ColumnChartView; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 13.03.2017 - * - * Interface between {@link HistoryActivity} and {@link HistoryFragment}. - */ -public interface IHistoryView { - /** - * Draws chart for given hrv value. - * @param chart to draw into. - * @param hrvValue to draw chart for. - * @param context in which to draw chart. - */ - void drawChart(ColumnChartView chart, HRVValue hrvValue, - Context context); - - /** - * Returns parameters of {@link HistoryActivity}. - * @return parameters. - */ - List getMeasurements(); - - /** - * Updates all {@link HistoryFragment} in {@link HistoryActivity}. - */ - void updateFragments(); -} diff --git a/app/src/main/java/hrv/band/app/view/control/chart/AbstractChartDrawStrategy.java b/app/src/main/java/hrv/band/app/view/control/chart/AbstractChartDrawStrategy.java deleted file mode 100644 index 84506f4..0000000 --- a/app/src/main/java/hrv/band/app/view/control/chart/AbstractChartDrawStrategy.java +++ /dev/null @@ -1,111 +0,0 @@ -package hrv.band.app.view.control.chart; - -import android.content.Context; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import hrv.band.app.control.Measurement; -import hrv.band.app.view.adapter.HRVValue; -import lecho.lib.hellocharts.model.Axis; -import lecho.lib.hellocharts.model.AxisValue; -import lecho.lib.hellocharts.model.Column; -import lecho.lib.hellocharts.model.ColumnChartData; -import lecho.lib.hellocharts.model.SubcolumnValue; -import lecho.lib.hellocharts.view.ColumnChartView; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 07.03.2017 - * - * Strategy to draw parameters into chart. - */ -public abstract class AbstractChartDrawStrategy { - Column[] columns; - protected Context context; - - /** - * Initialized the chart and showing the given parameters. - * @param measurements the parameters to show in the chart. - */ - public void drawChart(List measurements, ColumnChartView mChart, - HRVValue hrvValue, Context context) { - - this.context = context; - initChartValues(); - setChartValues(measurements, hrvValue); - setAxis(mChart, hrvValue); - } - - /** - * Sets the properties of the X and Y axis of the chart. - */ - private void setAxis(ColumnChartView mChart, HRVValue hrvValue) { - ColumnChartData data = new ColumnChartData(new ArrayList<>(Arrays.asList(columns))); - - Axis axisX = new Axis(); - Axis axisY = new Axis().setHasLines(true); - axisX.setName(getXAxisLabel()); - axisX.setValues(getXAxisValues()); - axisY.setName(hrvValue.getUnit()); - data.setAxisXBottom(axisX); - data.setAxisYLeft(axisY); - - mChart.setZoomEnabled(false); - mChart.setColumnChartData(data); - } - - /** - * Initializes the chart values. - */ - private void initChartValues() { - columns = new Column[getColumnCount()]; - for (int i = 0; i < getColumnCount(); i++) { - ArrayList subColumns = new ArrayList<>(); - for (int j = 0; j < getSubColumnCount(); j++) { - subColumns.add(new SubcolumnValue()); - } - columns[i] = new Column(subColumns); - } - } - - /** - * Configs the column labels. - * @param index of the column to config. - */ - void configColumnLabels(int index) { - columns[index].setHasLabels(false); - columns[index].setHasLabelsOnlyForSelected(false); - } - - /** - * Returns the label of the x axis. - * @return the label of the x axis. - */ - protected abstract String getXAxisLabel(); - - protected abstract List getXAxisValues(); - - /** - * Returns the column count. - * @return the column count. - */ - protected abstract int getColumnCount(); - - /** - * Returns the sub column count. - * @return the sub column count. - */ - protected abstract int getSubColumnCount(); - - /** - * Sets the values of the chart with the given parameters. - * @param parameters the parameters to show in the chart. - */ - protected abstract void setChartValues(List parameters, HRVValue hrvValue); - - - - -} diff --git a/app/src/main/java/hrv/band/app/view/control/chart/ChartDrawDayStrategy.java b/app/src/main/java/hrv/band/app/view/control/chart/ChartDrawDayStrategy.java deleted file mode 100644 index 35de5df..0000000 --- a/app/src/main/java/hrv/band/app/view/control/chart/ChartDrawDayStrategy.java +++ /dev/null @@ -1,79 +0,0 @@ -package hrv.band.app.view.control.chart; - -import android.support.v4.content.ContextCompat; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.EnumSet; -import java.util.GregorianCalendar; -import java.util.List; - -import hrv.HRVLibFacade; -import hrv.RRData; -import hrv.band.app.R; -import hrv.band.app.control.Measurement; -import hrv.band.app.view.adapter.HRVValue; -import lecho.lib.hellocharts.model.AxisValue; -import lecho.lib.hellocharts.model.SubcolumnValue; -import units.TimeUnit; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 07.03.2017 - * - * Draws parameters into chart which were measured on that day. - */ -public class ChartDrawDayStrategy extends AbstractChartDrawStrategy { - - private static final int COLUMN_COUNT = 24; - private static final int SUB_COLUMN_COUNT = 4; - private static final String X_AXIS_LABEL = "Hour"; - - @Override - protected void setChartValues(List measurements, HRVValue hrvValueType) { - Calendar calendar = GregorianCalendar.getInstance(); - for (Measurement measurement : measurements) { - calendar.setTime(measurement.getTime()); - int hour = calendar.get(Calendar.HOUR_OF_DAY); - int minutes = calendar.get(Calendar.MINUTE) / 15; - - HRVLibFacade hrvCalc = new HRVLibFacade(RRData.createFromRRInterval(measurement.getRRIntervals(), TimeUnit.SECOND)); - hrvCalc.setParameters(EnumSet.of(hrvValueType.getHRVparam())); - double value = hrvCalc.calculateParameters().get(0).getValue(); - - columns[hour].getValues().set(minutes, - new SubcolumnValue((float) value, - ContextCompat.getColor(context, R.color.colorAccent))); - configColumnLabels(hour); - } - } - - @Override - protected int getColumnCount() { - return COLUMN_COUNT; - } - - @Override - protected int getSubColumnCount() { - return SUB_COLUMN_COUNT; - } - - @Override - protected String getXAxisLabel() { - return X_AXIS_LABEL; - } - - @Override - protected List getXAxisValues() { - List values = new ArrayList<>(); - for (int i = 0; i < COLUMN_COUNT; i++) { - AxisValue value = new AxisValue(i); - if (i % 4 == 0) { - value.setLabel(i + ":00"); - values.add(value); - } - } - return values; - } - -} diff --git a/app/src/main/java/hrv/band/app/view/control/chart/ChartDrawMonthStrategy.java b/app/src/main/java/hrv/band/app/view/control/chart/ChartDrawMonthStrategy.java deleted file mode 100644 index 5a768a0..0000000 --- a/app/src/main/java/hrv/band/app/view/control/chart/ChartDrawMonthStrategy.java +++ /dev/null @@ -1,85 +0,0 @@ -package hrv.band.app.view.control.chart; - -import android.support.v4.content.ContextCompat; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.EnumSet; -import java.util.GregorianCalendar; -import java.util.List; - -import hrv.HRVLibFacade; -import hrv.RRData; -import hrv.band.app.R; -import hrv.band.app.control.Measurement; -import hrv.band.app.view.adapter.HRVValue; -import lecho.lib.hellocharts.model.AxisValue; -import lecho.lib.hellocharts.model.SubcolumnValue; -import units.TimeUnit; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 07.03.2017 - * - * Draws parameters into chart which were measured in that month. - */ -public class ChartDrawMonthStrategy extends AbstractChartDrawStrategy { - - private int columnCount; - private static final int SUB_COLUMN_COUNT = 0; - private static final String X_AXIS_LABEL = "Date"; - - public ChartDrawMonthStrategy(Date date) { - Calendar calendar = GregorianCalendar.getInstance(); // creates a new calendar instance - calendar.setTime(date); - columnCount = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); - } - - @Override - protected void setChartValues(List measurements, HRVValue hrvValueType) { - Calendar calendar = GregorianCalendar.getInstance(); - calendar.setFirstDayOfWeek(Calendar.MONDAY); - for (Measurement measurement : measurements) { - calendar.setTime(measurement.getTime()); - int day = calendar.get(Calendar.DAY_OF_MONTH) - 1; - - HRVLibFacade hrvCalc = new HRVLibFacade(RRData.createFromRRInterval(measurement.getRRIntervals(), TimeUnit.SECOND)); - hrvCalc.setParameters(EnumSet.of(hrvValueType.getHRVparam())); - double value = hrvCalc.calculateParameters().get(0).getValue(); - - columns[day].getValues().add( - new SubcolumnValue((float) value, - ContextCompat.getColor(context, R.color.colorAccent))); - configColumnLabels(day); - } - } - - @Override - protected int getColumnCount() { - return columnCount; - } - - @Override - protected int getSubColumnCount() { - return SUB_COLUMN_COUNT; - } - - @Override - protected String getXAxisLabel() { - return X_AXIS_LABEL; - } - - @Override - protected List getXAxisValues() { - List values = new ArrayList<>(); - for (int i = 1; i <= columnCount; i++) { - AxisValue value = new AxisValue(i); - if (i % 5 == 0) { - value.setLabel(Integer.toString(i) + ""); - values.add(value); - } - } - return values; - } -} diff --git a/app/src/main/java/hrv/band/app/view/control/chart/ChartDrawWeekStrategy.java b/app/src/main/java/hrv/band/app/view/control/chart/ChartDrawWeekStrategy.java deleted file mode 100644 index fa7b433..0000000 --- a/app/src/main/java/hrv/band/app/view/control/chart/ChartDrawWeekStrategy.java +++ /dev/null @@ -1,94 +0,0 @@ -package hrv.band.app.view.control.chart; - -import android.content.res.Resources; -import android.support.v4.content.ContextCompat; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.EnumSet; -import java.util.GregorianCalendar; -import java.util.List; - -import hrv.HRVLibFacade; -import hrv.RRData; -import hrv.band.app.R; -import hrv.band.app.control.Measurement; -import hrv.band.app.view.adapter.HRVValue; -import lecho.lib.hellocharts.model.AxisValue; -import lecho.lib.hellocharts.model.SubcolumnValue; -import units.TimeUnit; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 07.03.2017 - * - * Draws parameters into chart which were measured on that week. - */ -public class ChartDrawWeekStrategy extends AbstractChartDrawStrategy { - - private static final int COLUMN_COUNT = 7; - private static final int SUB_COLUMN_COUNT = 0; - private static final String X_AXIS_LABEL = "Day"; - - @Override - protected void setChartValues(List measurements, HRVValue hrvValueType) { - Calendar calendar = GregorianCalendar.getInstance(); - calendar.setFirstDayOfWeek(Calendar.MONDAY); - - for (Measurement measurement : measurements) { - calendar.setTime(measurement.getTime()); - - //Minus 2 because get always returns 1 for sunday. - int day = calendar.get(Calendar.DAY_OF_WEEK) - 2; - //If day == sunday, make it the last day of the week. - if(day == -1) { - day = 6; - } - - HRVLibFacade hrvCalc = new HRVLibFacade(RRData.createFromRRInterval(measurement.getRRIntervals(), TimeUnit.SECOND)); - hrvCalc.setParameters(EnumSet.of(hrvValueType.getHRVparam())); - double value = hrvCalc.calculateParameters().get(0).getValue(); - - columns[day].getValues().add( - new SubcolumnValue((float) value, - ContextCompat.getColor(context, R.color.colorAccent))); - configColumnLabels(day); - } - } - - @Override - protected int getColumnCount() { - return COLUMN_COUNT; - } - - @Override - protected int getSubColumnCount() { - return SUB_COLUMN_COUNT; - } - - @Override - protected String getXAxisLabel() { - return X_AXIS_LABEL; - } - - @Override - protected List getXAxisValues() { - Resources resources = context.getResources(); - List values = new ArrayList<>(); - AxisValue value = new AxisValue(0); - values.add(value.setLabel(resources.getString(R.string.monday_sc))); - value = new AxisValue(1); - values.add(value.setLabel(resources.getString(R.string.tuesday_sc))); - value = new AxisValue(2); - values.add(value.setLabel(resources.getString(R.string.wednesday_sc))); - value = new AxisValue(3); - values.add(value.setLabel(resources.getString(R.string.thursday_sc))); - value = new AxisValue(4); - values.add(value.setLabel(resources.getString(R.string.friday_sc))); - value = new AxisValue(5); - values.add(value.setLabel(resources.getString(R.string.saturday_sc))); - value = new AxisValue(6); - values.add(value.setLabel(resources.getString(R.string.sunday_sc))); - return values; - } -} diff --git a/app/src/main/java/hrv/band/app/view/control/parameter/AbstractParameterLoadStrategy.java b/app/src/main/java/hrv/band/app/view/control/parameter/AbstractParameterLoadStrategy.java deleted file mode 100644 index 10be8e2..0000000 --- a/app/src/main/java/hrv/band/app/view/control/parameter/AbstractParameterLoadStrategy.java +++ /dev/null @@ -1,28 +0,0 @@ -package hrv.band.app.view.control.parameter; - -import android.content.Context; - -import java.util.Date; -import java.util.List; - -import hrv.band.app.control.Measurement; -import hrv.band.app.storage.IStorage; -import hrv.band.app.storage.sqlite.HRVSQLController; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 25.03.2017 - * - * Strategy to select parameters from db. - */ -public abstract class AbstractParameterLoadStrategy { - protected IStorage storage = new HRVSQLController(); - - /** - * Loads parameters from db. - * @param context for db selection. - * @param date from which to select parameters. - * @return parameters from db. - */ - public abstract List loadParameter(Context context, Date date); -} diff --git a/app/src/main/java/hrv/band/app/view/control/parameter/ParameterLoadDayStrategy.java b/app/src/main/java/hrv/band/app/view/control/parameter/ParameterLoadDayStrategy.java deleted file mode 100644 index 803a1d7..0000000 --- a/app/src/main/java/hrv/band/app/view/control/parameter/ParameterLoadDayStrategy.java +++ /dev/null @@ -1,22 +0,0 @@ -package hrv.band.app.view.control.parameter; - -import android.content.Context; - -import java.util.Date; -import java.util.List; - -import hrv.band.app.control.Measurement; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 25.03.2017 - * - * Loads parameters of given date. - */ -public class ParameterLoadDayStrategy extends AbstractParameterLoadStrategy { - - @Override - public List loadParameter(Context context, Date date) { - return storage.loadData(context, date); - } -} \ No newline at end of file diff --git a/app/src/main/java/hrv/band/app/view/control/parameter/ParameterLoadMonthStrategy.java b/app/src/main/java/hrv/band/app/view/control/parameter/ParameterLoadMonthStrategy.java deleted file mode 100644 index 413080f..0000000 --- a/app/src/main/java/hrv/band/app/view/control/parameter/ParameterLoadMonthStrategy.java +++ /dev/null @@ -1,35 +0,0 @@ -package hrv.band.app.view.control.parameter; - -import android.content.Context; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.List; - -import hrv.band.app.control.Measurement; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 25.03.2017 - * - * Loads parameter of given month. - */ -public class ParameterLoadMonthStrategy extends AbstractParameterLoadStrategy { - - @Override - public List loadParameter(Context context, Date date) { - Calendar calendar = GregorianCalendar.getInstance(); // creates a new calendar instance - calendar.setFirstDayOfWeek(Calendar.MONDAY); - calendar.setTime(date); - calendar.set(Calendar.DAY_OF_MONTH, 1); - int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); - List result = new ArrayList<>(); - for (int i = 0; i < daysInMonth; i++) { - result.addAll(storage.loadData(context, calendar.getTime())); - calendar.add(Calendar.DAY_OF_MONTH, 1); - } - return result; - } -} \ No newline at end of file diff --git a/app/src/main/java/hrv/band/app/view/control/parameter/ParameterLoadWeekStrategy.java b/app/src/main/java/hrv/band/app/view/control/parameter/ParameterLoadWeekStrategy.java deleted file mode 100644 index 54684d5..0000000 --- a/app/src/main/java/hrv/band/app/view/control/parameter/ParameterLoadWeekStrategy.java +++ /dev/null @@ -1,33 +0,0 @@ -package hrv.band.app.view.control.parameter; - -import android.content.Context; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.List; - -import hrv.band.app.control.Measurement; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 25.03.2017 - * - * Loads parameter from given week. - */ -public class ParameterLoadWeekStrategy extends AbstractParameterLoadStrategy { - - @Override - public List loadParameter(Context context, Date date) { - Calendar calendar = GregorianCalendar.getInstance(); // creates a new calendar instance - calendar.setTime(date); - calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); - List result = new ArrayList<>(); - for (int i = 0; i < 7; i++) { - result.addAll(storage.loadData(context, calendar.getTime())); - calendar.add(Calendar.DAY_OF_MONTH, 1); - } - return result; - } -} \ No newline at end of file diff --git a/app/src/main/java/hrv/band/app/view/fragment/AboutFragment.java b/app/src/main/java/hrv/band/app/view/fragment/AboutFragment.java deleted file mode 100644 index 160cd8f..0000000 --- a/app/src/main/java/hrv/band/app/view/fragment/AboutFragment.java +++ /dev/null @@ -1,38 +0,0 @@ -package hrv.band.app.view.fragment; - -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import hrv.band.app.R; -import hrv.band.app.view.activity.ImprintActivity; -import hrv.band.app.view.presenter.AboutPresenter; -import hrv.band.app.view.presenter.IAboutPresenter; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 19.01.2017 - * - * First Fragment in {@link ImprintActivity} showing imprint. - */ -public class AboutFragment extends Fragment{ - - public static AboutFragment newInstance() { - return new AboutFragment(); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View rootView = inflater.inflate(R.layout.imprint_fragment_about, container, false); - IAboutPresenter presenter = new AboutPresenter(getActivity()); - - TextView version = (TextView) rootView.findViewById(R.id.about_version); - version.setText(presenter.getVersion()); - - return rootView; - } -} diff --git a/app/src/main/java/hrv/band/app/view/fragment/CancelMeasuringDialogFragment.java b/app/src/main/java/hrv/band/app/view/fragment/CancelMeasuringDialogFragment.java deleted file mode 100644 index 17eb61d..0000000 --- a/app/src/main/java/hrv/band/app/view/fragment/CancelMeasuringDialogFragment.java +++ /dev/null @@ -1,55 +0,0 @@ -package hrv.band.app.view.fragment; - -import android.app.Activity; -import android.app.AlertDialog; -import android.app.Dialog; -import android.app.DialogFragment; -import android.content.DialogInterface; -import android.os.Bundle; -import android.view.View; -import android.widget.TextView; - -import hrv.band.app.R; -import hrv.band.app.view.activity.MainActivity; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 19.01.2017 - * - * This dialog allows the user to cancel the measurement. - */ -public class CancelMeasuringDialogFragment extends DialogFragment { - - public static CancelMeasuringDialogFragment newInstance() { - return new CancelMeasuringDialogFragment(); - } - - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - - final View view = View.inflate(getActivity(), R.layout.dialog_simple_text, null); - - TextView textView = (TextView) view.findViewById(R.id.dialog_textview); - textView.setText(getResources().getString(R.string.measure_cancel_desc)); - - builder.setView(view) - .setPositiveButton(R.string.common_yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - Activity activity = getActivity(); - if (activity instanceof MainActivity) { - ((MainActivity) getActivity()).stopMeasuring(); - } - } - }) - .setNegativeButton(R.string.common_no, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - CancelMeasuringDialogFragment.this.getDialog().cancel(); - } - }); - builder.setTitle(getResources().getString(R.string.measure_cancel_title)); - return builder.create(); - } -} diff --git a/app/src/main/java/hrv/band/app/view/fragment/DisclaimerFragment.java b/app/src/main/java/hrv/band/app/view/fragment/DisclaimerFragment.java deleted file mode 100644 index 1542951..0000000 --- a/app/src/main/java/hrv/band/app/view/fragment/DisclaimerFragment.java +++ /dev/null @@ -1,33 +0,0 @@ -package hrv.band.app.view.fragment; - -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import hrv.band.app.R; -import hrv.band.app.view.activity.ImprintActivity; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 19.01.2017 - * - * Fragment showing the disclaimer in the {@link ImprintActivity}. - */ -public class DisclaimerFragment extends Fragment { - - /** - * Returns a new instance of this fragment. - * @return a new instance of this fragment. - */ - public static DisclaimerFragment newInstance() { - return new DisclaimerFragment(); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - return inflater.inflate(R.layout.imprint_fragment_disclaimer, container, false); - } -} diff --git a/app/src/main/java/hrv/band/app/view/fragment/ExportFragment.java b/app/src/main/java/hrv/band/app/view/fragment/ExportFragment.java deleted file mode 100644 index e72144e..0000000 --- a/app/src/main/java/hrv/band/app/view/fragment/ExportFragment.java +++ /dev/null @@ -1,80 +0,0 @@ -package hrv.band.app.view.fragment; - -import android.app.AlertDialog; -import android.app.Dialog; -import android.app.DialogFragment; -import android.content.DialogInterface; -import android.os.Bundle; -import android.util.Log; -import android.view.View; -import android.widget.TextView; -import android.widget.Toast; - -import java.io.IOException; - -import hrv.band.app.R; -import hrv.band.app.storage.sqlite.HRVSQLController; - -/** - * Copyright (c) 2017 - * Created by Julian Martin on 19.01.2017 - * - * Dialog asking the user to export his data. - */ -public class ExportFragment extends DialogFragment { - - public static ExportFragment newInstance() { - return new ExportFragment(); - } - - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - - final View view = View.inflate(getActivity(), R.layout.dialog_simple_text, null); - - TextView textView = (TextView) view.findViewById(R.id.dialog_textview); - textView.setText(getResources().getString(R.string.sentence_export_db)); - - - builder.setView(view) - .setPositiveButton(R.string.common_export, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - exportDB(); - } - }) - .setNegativeButton(R.string.common_cancel, new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - ExportFragment.this.getDialog().cancel(); - } - }); - builder.setTitle(getResources().getString(R.string.common_export)); - return builder.create(); - } - - /** - * Exports the user database on the phone. - */ - private void exportDB() { - HRVSQLController sql = new HRVSQLController(); - try { - int duration = Toast.LENGTH_SHORT; - - if(!sql.exportDB(getActivity())) { - CharSequence text = getResources().getText(R.string.sentence_export_failed); - Toast toast = Toast.makeText(getActivity().getApplicationContext(), text, duration); - toast.show(); - } - else { - CharSequence text = getResources().getText(R.string.sentence_export_worked); - Toast toast = Toast.makeText(getActivity().getApplicationContext(), text, duration); - toast.show(); - } - } catch (IOException e) { - Log.e(e.getClass().getName(), "IOException", e); - } - } -} diff --git a/app/src/main/java/hrv/band/app/view/fragment/FeedbackDialogFragment.java b/app/src/main/java/hrv/band/app/view/fragment/FeedbackDialogFragment.java deleted file mode 100644 index 6711daa..0000000 --- a/app/src/main/java/hrv/band/app/view/fragment/FeedbackDialogFragment.java +++ /dev/null @@ -1,111 +0,0 @@ -package hrv.band.app.view.fragment; - -import android.app.AlertDialog; -import android.app.Dialog; -import android.content.DialogInterface; -import android.content.Intent; -import android.net.Uri; -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v4.app.DialogFragment; -import android.view.View; -import android.widget.EditText; -import android.widget.Spinner; - -import hrv.band.app.R; -import hrv.band.app.view.adapter.FeedbackCategoryAdapter; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 19.01.2017 - * - * Dialog asking the user for feedback. - */ -public class FeedbackDialogFragment extends DialogFragment { - private static final String FEEDBACK_EMAIL = "hrvband+feedback@gmail.com"; - private View view; - - /** - * Returns a new instance of this fragment. - * @return a new instance of this fragment. - */ - public static FeedbackDialogFragment newInstance() { - return new FeedbackDialogFragment(); - } - - @NonNull - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - - view = View.inflate(getActivity(), R.layout.dialog_feedback, null); - - builder.setView(view) - // Add action buttons - .setPositiveButton(R.string.feedback_send, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - Intent email = new Intent(Intent.ACTION_SENDTO, Uri.fromParts( - "mailto", FEEDBACK_EMAIL, null)); - email.putExtra(Intent.EXTRA_SUBJECT, getSubject()); - email.putExtra(Intent.EXTRA_TEXT, getText()); - startActivity(Intent.createChooser(email, "send feedback")); - } - }) - .setNegativeButton(R.string.feedback_cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - FeedbackDialogFragment.this.getDialog().cancel(); - } - }); - builder.setTitle("Feedback"); - setSpinnerValues(view); - return builder.create(); - } - - /** - * Sets the spinner values with possible subjects the user can choose. - * @param view te view holding the spinner. - */ - private void setSpinnerValues(View view) { - Spinner spinner = (Spinner) view.findViewById(R.id.feedback_category); - spinner.setAdapter(new FeedbackCategoryAdapter(getActivity().getApplicationContext())); - } - - /** - * Returns the subject of the feedback the user entered. - * @return the subject of the feedback the user entered. - */ - private String getSubject() { - if (view == null) { - return ""; - } - Spinner spinner = (Spinner) view.findViewById(R.id.feedback_category); - String subject = FeedbackCategoryAdapter.FeedbackCategory.values()[spinner.getSelectedItemPosition()].getText(getResources()); - return "Feedback - [" + subject + "]"; - } - - /** - * Returns the message of the user. - * @return the message of the user. - */ - private String getText() { - EditText text = (EditText) view.findViewById(R.id.feedback_text); - return text.getText() + "\n" + getDeviceInformation(); - } - - /** - * Returns the device information of the user phone. - * @return the device information of the user phone. - */ - private String getDeviceInformation() { - String info = "Debug-infos:"; - info += "\n OS Version: " + System.getProperty("os.version") + "(" + android.os.Build.VERSION.INCREMENTAL + ")"; - info += "\n OS API Level: " + android.os.Build.VERSION.SDK_INT; - info += "\n Device: " + android.os.Build.DEVICE; - info += "\n Model (and Product): " + android.os.Build.MODEL + " ("+ android.os.Build.PRODUCT + ")"; - return info; - } - - -} diff --git a/app/src/main/java/hrv/band/app/view/fragment/FragmentObserver.java b/app/src/main/java/hrv/band/app/view/fragment/FragmentObserver.java deleted file mode 100644 index 0aa3b30..0000000 --- a/app/src/main/java/hrv/band/app/view/fragment/FragmentObserver.java +++ /dev/null @@ -1,17 +0,0 @@ -package hrv.band.app.view.fragment; - -import java.util.Observable; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 13.03.2017 - */ - - -public class FragmentObserver extends Observable { - @Override - public void notifyObservers() { - setChanged(); // Set the changed flag to true, otherwise observers won't be notified. - super.notifyObservers(); - } -} diff --git a/app/src/main/java/hrv/band/app/view/fragment/HistoryFragment.java b/app/src/main/java/hrv/band/app/view/fragment/HistoryFragment.java deleted file mode 100644 index 23ded38..0000000 --- a/app/src/main/java/hrv/band/app/view/fragment/HistoryFragment.java +++ /dev/null @@ -1,129 +0,0 @@ -package hrv.band.app.view.fragment; - -import android.content.Context; -import android.content.Intent; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.ListView; -import android.widget.TextView; - -import java.util.List; -import java.util.Observable; -import java.util.Observer; - -import hrv.band.app.R; -import hrv.band.app.control.Measurement; -import hrv.band.app.view.activity.HRVValueActivity; -import hrv.band.app.view.activity.MainActivity; -import hrv.band.app.view.adapter.HRVValue; -import hrv.band.app.view.adapter.StatisticValueAdapter; -import hrv.band.app.view.control.IHistoryView; -import lecho.lib.hellocharts.view.ColumnChartView; - -import static hrv.band.app.view.activity.HistoryActivity.RESULT_DELETED; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 19.01.2017 - * - * Fragment allowing user to start measurement. - */ -public class HistoryFragment extends Fragment implements Observer { - - /** Key value for the hrv type of this fragment. **/ - private static final String ARG_SECTION_VALUE = "sectionValue"; - /** The adapter holding the parameters to show. **/ - private StatisticValueAdapter adapter; - /** The chart showing the parameters in this fragment. **/ - private ColumnChartView mChart; - /** The hrv type that this fragment is showing. **/ - private HRVValue hrvType; - /** The parameters this fragment should show. **/ - private List parameters; - - private IHistoryView statisticListener; - - /** - * Returns a new instance of this fragment. - * @return a new instance of this fragment. - */ - public static HistoryFragment newInstance(HRVValue type) { - HistoryFragment fragment = new HistoryFragment(); - Bundle args = new Bundle(); - args.putSerializable(ARG_SECTION_VALUE, type); - fragment.setArguments(args); - return fragment; - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View rootView = inflater.inflate(R.layout.statistic_fragment, container, false); - ListView listView = (ListView) rootView.findViewById(R.id.stats_measure_history); - - if (statisticListener != null) { - parameters = statisticListener.getMeasurements(); - } - hrvType = (HRVValue) getArguments().getSerializable(ARG_SECTION_VALUE); - - TextView desc = (TextView) rootView.findViewById(R.id.stats_value_desc); - TextView type = (TextView) rootView.findViewById(R.id.stats_type); - - desc.setText(hrvType.toString()); - type.setText(hrvType.getUnit()); - - - adapter = new StatisticValueAdapter(getActivity().getApplicationContext(), - hrvType, parameters); - listView.setAdapter(adapter); - - listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { - - @Override - public void onItemClick(AdapterView parent, final View view, - int position, long id) { - Intent intent = new Intent(getContext(), HRVValueActivity.class); - intent.putExtra(MainActivity.HRV_PARAMETER_ID, parameters.get(position)); - startActivityForResult(intent, 1); - } - - }); - - mChart = (ColumnChartView) rootView.findViewById(R.id.stats_chart); - - if (statisticListener != null) { - statisticListener.drawChart(mChart, hrvType, getActivity()); - } - return rootView; - } - - @Override - public void onAttach(Context context) { - super.onAttach(context); - if (context instanceof IHistoryView) { - statisticListener = (IHistoryView) context; - } - } - - @Override - public void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if(resultCode == RESULT_DELETED){ - statisticListener.updateFragments(); - } - } - - @Override - public void update(Observable observable, Object o) { - parameters = statisticListener.getMeasurements(); - if (adapter != null) { - adapter.setDataset(parameters); - adapter.notifyDataSetChanged(); - statisticListener.drawChart(mChart, hrvType, getActivity()); - } - } -} diff --git a/app/src/main/java/hrv/band/app/view/fragment/ISettingsView.java b/app/src/main/java/hrv/band/app/view/fragment/ISettingsView.java deleted file mode 100644 index 1acceee..0000000 --- a/app/src/main/java/hrv/band/app/view/fragment/ISettingsView.java +++ /dev/null @@ -1,19 +0,0 @@ -package hrv.band.app.view.fragment; - -import android.app.Activity; -import android.view.View; - -/** - * Copyright (c) 2017 - * Created by Thomas on 15.04.2017. - */ - -public interface ISettingsView { - Activity getSettingsActivity(); - - void showSnackbar(int messageId, View.OnClickListener clickListener); - - void showAlertDialog(int titleId, int messageId); - - void startExportFragment(); -} diff --git a/app/src/main/java/hrv/band/app/view/fragment/IntroFragment.java b/app/src/main/java/hrv/band/app/view/fragment/IntroFragment.java deleted file mode 100644 index 1669e6a..0000000 --- a/app/src/main/java/hrv/band/app/view/fragment/IntroFragment.java +++ /dev/null @@ -1,65 +0,0 @@ -package hrv.band.app.view.fragment; - -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; - -import hrv.band.app.R; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 19.01.2017 - * - * Fragment showing one intro page. - */ -public class IntroFragment extends Fragment { - - /** Key value for the tutorial title of this intro page (fragment). **/ - private static final String INTRO_TITLE_ID = "intro_title_id"; - /** Key value for the tutorial description of this intro page (fragment). **/ - private static final String INTRO_DESC_ID = "intro_desc_id"; - /** Key value for the tutorial image of this intro page (fragment). **/ - private static final String INTRO_IMAGE_ID = "intro_image_id"; - - /** - * Returns a new instance of this fragment. - * @return a new instance of this fragment. - */ - public static IntroFragment newInstance(String title, String desc, int imageId) { - IntroFragment fragment = new IntroFragment(); - Bundle args = new Bundle(); - args.putString(INTRO_TITLE_ID, title); - args.putString(INTRO_DESC_ID, desc); - args.putInt(INTRO_IMAGE_ID, imageId); - fragment.setArguments(args); - return fragment; - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View rootView = inflater.inflate(R.layout.intro_fragment, container, false); - - TextView title = (TextView) rootView.findViewById(R.id.intro_title); - ImageView image = (ImageView) rootView.findViewById(R.id.intro_image); - TextView desc = (TextView) rootView.findViewById(R.id.intro_desc); - - title.setText(getArguments().getString(INTRO_TITLE_ID)); - - BitmapFactory.Options o = new BitmapFactory.Options(); - o.inSampleSize = 2; - - Bitmap img = BitmapFactory.decodeResource(getResources(), getArguments().getInt(INTRO_IMAGE_ID), o); - image.setImageBitmap(img); - - desc.setText(getArguments().getString(INTRO_DESC_ID)); - - return rootView; - } -} diff --git a/app/src/main/java/hrv/band/app/view/fragment/LicenseFragment.java b/app/src/main/java/hrv/band/app/view/fragment/LicenseFragment.java deleted file mode 100644 index 0ac4584..0000000 --- a/app/src/main/java/hrv/band/app/view/fragment/LicenseFragment.java +++ /dev/null @@ -1,41 +0,0 @@ -package hrv.band.app.view.fragment; - -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ListView; - -import hrv.band.app.R; -import hrv.band.app.view.adapter.LicenseAdapter; - - -/** - * Copyright (c) 2017 - * Created by Julian Martin on 19.01.2017 - * - * Fragment holding the licenses of the used libaries. - */ -public class LicenseFragment extends Fragment { - - /** - * Returns a new instance of this fragment. - * @return a new instance of this fragment. - */ - public static LicenseFragment newInstance() { - return new LicenseFragment(); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View rootView = inflater.inflate(R.layout.imprint_fragment_license, container, false); - - ListView listview = (ListView) rootView.findViewById(R.id.licence_list); - LicenseAdapter adapter = new LicenseAdapter(this.getActivity()); - listview.setAdapter(adapter); - - return rootView; - } -} \ No newline at end of file diff --git a/app/src/main/java/hrv/band/app/view/fragment/MeasuredDetailsEditFragment.java b/app/src/main/java/hrv/band/app/view/fragment/MeasuredDetailsEditFragment.java deleted file mode 100644 index f34adfa..0000000 --- a/app/src/main/java/hrv/band/app/view/fragment/MeasuredDetailsEditFragment.java +++ /dev/null @@ -1,92 +0,0 @@ -package hrv.band.app.view.fragment; - -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.RatingBar; -import android.widget.Spinner; -import android.widget.TextView; - -import hrv.band.app.R; -import hrv.band.app.view.adapter.AbstractCategoryAdapter; -import hrv.band.app.view.adapter.MeasurementCategoryAdapter; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 19.01.2017 - * - * Fragment allowing the user to set the details of a measurement. - */ -public class MeasuredDetailsEditFragment extends Fragment implements IMeasuredDetails{ - - /** rootView of this Fragment. **/ - private View rootView; - - /** - * Returns a new instance of this fragment. - * @return a new instance of this fragment. - */ - public static MeasuredDetailsEditFragment newInstance() { - return new MeasuredDetailsEditFragment(); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - rootView = inflater.inflate(R.layout.hrv_measurement_fragment_details, container, false); - - Spinner spinner = (Spinner) rootView.findViewById(R.id.measure_categories); - AbstractCategoryAdapter spinnerArrayAdapter = new MeasurementCategoryAdapter(getContext()); - - spinner.setAdapter(spinnerArrayAdapter); - - return rootView; - } - - /** - * Returns the rating of the user for the actual measurement. - * @return the rating of the user for the actual measurement. - */ - @Override - public float getRating() { - if (rootView == null) { - return 0; - } - RatingBar ratingbar = (RatingBar) rootView.findViewById(R.id.measure_rating); - return ratingbar.getRating(); - } - - /** - * Returns the chosen category. - * @return the chosen category. - */ - @Override - public MeasurementCategoryAdapter.MeasureCategory getCategory() { - if (rootView == null) { - return MeasurementCategoryAdapter.MeasureCategory.GENERAL; - } - Spinner spinner = (Spinner) rootView.findViewById(R.id.measure_categories); - int position = spinner.getSelectedItemPosition(); - return MeasurementCategoryAdapter.MeasureCategory.values()[position]; - } - - /** - * Returns the note the user entered. - * @return the note the user entered. - */ - @Override - public String getNote() { - if (rootView == null) { - return ""; - } - TextView note = (TextView) rootView.findViewById(R.id.measure_note); - return note.getText().toString(); - } - - @Override - public Fragment getFragment() { - return this; - } -} diff --git a/app/src/main/java/hrv/band/app/view/fragment/MeasuredDetailsFragment.java b/app/src/main/java/hrv/band/app/view/fragment/MeasuredDetailsFragment.java deleted file mode 100644 index 8ed25bc..0000000 --- a/app/src/main/java/hrv/band/app/view/fragment/MeasuredDetailsFragment.java +++ /dev/null @@ -1,61 +0,0 @@ -package hrv.band.app.view.fragment; - -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; - -import hrv.band.app.control.Measurement; -import hrv.band.app.R; -import hrv.band.app.view.activity.MainActivity; -import hrv.band.app.view.presenter.IMeasurementDetailsPresenter; -import hrv.band.app.view.presenter.MeasurementDetailsPresenter; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 19.01.2017 - * - * Fragment showing the details of a measurement. - */ -public class MeasuredDetailsFragment extends Fragment { - - /** - * Returns a new instance of this fragment. - * - * @param parameter the hrv parameter to get details from. - * @return a new instance of this fragment. - */ - public static MeasuredDetailsFragment newInstance(Measurement parameter) { - MeasuredDetailsFragment fragment = new MeasuredDetailsFragment(); - Bundle args = new Bundle(); - args.putParcelable(MainActivity.HRV_VALUE, parameter); - fragment.setArguments(args); - return fragment; - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View rootView = inflater.inflate(R.layout.hrv_value_fragment_details, container, false); - - IMeasurementDetailsPresenter presenter = new MeasurementDetailsPresenter( - (Measurement) getArguments().getParcelable(MainActivity.HRV_VALUE), getActivity()); - - TextView dateTxt = (TextView) rootView.findViewById(R.id.hrv_date); - TextView ratingTxt = (TextView) rootView.findViewById(R.id.hrv_rating); - TextView categoryTxt = (TextView) rootView.findViewById(R.id.hrv_category); - ImageView categoryIcon = (ImageView) rootView.findViewById(R.id.hrv_category_icon); - TextView commentTxt = (TextView) rootView.findViewById(R.id.hrv_comment); - - dateTxt.setText(presenter.getDate()); - ratingTxt.setText(presenter.getRating()); - categoryTxt.setText(presenter.getCategory()); - categoryIcon.setImageDrawable(presenter.getCategoryIcon()); - commentTxt.setText(presenter.getNote()); - - return rootView; - } -} diff --git a/app/src/main/java/hrv/band/app/view/fragment/MeasuredRRFragment.java b/app/src/main/java/hrv/band/app/view/fragment/MeasuredRRFragment.java deleted file mode 100644 index d90f1ff..0000000 --- a/app/src/main/java/hrv/band/app/view/fragment/MeasuredRRFragment.java +++ /dev/null @@ -1,123 +0,0 @@ -package hrv.band.app.view.fragment; - -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.support.v4.content.ContextCompat; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import java.util.ArrayList; -import java.util.List; - -import hrv.band.app.control.Measurement; -import hrv.band.app.R; -import hrv.band.app.view.activity.MainActivity; -import hrv.band.app.view.presenter.IRRPresenter; -import hrv.band.app.view.presenter.MeasuredRRPresenter; -import lecho.lib.hellocharts.model.Axis; -import lecho.lib.hellocharts.model.Column; -import lecho.lib.hellocharts.model.ColumnChartData; -import lecho.lib.hellocharts.model.SubcolumnValue; -import lecho.lib.hellocharts.view.ColumnChartView; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 19.01.2017 - * - * Fragment showing the rr intervals of a measurement. - */ -public class MeasuredRRFragment extends Fragment { - - /** The chart showing rr intervals **/ - private ColumnChartView mChart; - - private IRRPresenter presenter; - - /** - * Returns a new instance of this fragment. - * @param parameter the hrv parameter to get rr intervals from. - * @return a new instance of this fragment. - */ - public static MeasuredRRFragment newInstance(Measurement parameter) { - MeasuredRRFragment fragment = new MeasuredRRFragment(); - Bundle args = new Bundle(); - args.putParcelable(MainActivity.HRV_VALUE, parameter); - fragment.setArguments(args); - return fragment; - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View rootView = inflater.inflate(R.layout.abstract_hrv_fragment_rr, container, false); - - presenter = new MeasuredRRPresenter((Measurement) getArguments().getParcelable(MainActivity.HRV_VALUE)); - presenter.calculateRRStatistic(); - - mChart = (ColumnChartView) rootView.findViewById(R.id.rr_chart); - - if (presenter.getMeasurement() != null) { - initRRChart(); - setRRStatistic(rootView); - } - - return rootView; - } - - private void setRRStatistic(View rootView) { - - TextView minTxt = (TextView) rootView.findViewById(R.id.rr_min); - TextView maxTxt = (TextView) rootView.findViewById(R.id.rr_max); - TextView averageTxt = (TextView) rootView.findViewById(R.id.rr_average); - TextView countTxt = (TextView) rootView.findViewById(R.id.rr_count); - - minTxt.setText(presenter.getRRMin()); - maxTxt.setText(presenter.getRRMax()); - averageTxt.setText(presenter.getRRAverage()); - countTxt.setText(presenter.getRRCount()); - } - - /** - * Initialized chart showing rr intervals from hrv measurement. - */ - private void initRRChart() { - List columns = createChartData(); - setChartData(columns); - } - - private List createChartData() { - List columns = new ArrayList<>(); - List values; - double[] rrIntervals = presenter.getMeasurement().getRRIntervals(); - for (double rrInterval : rrIntervals) { - - values = new ArrayList<>(); - values.add(new SubcolumnValue((float) rrInterval, - ContextCompat.getColor(getContext(), R.color.colorAccent))); - - Column column = new Column(values); - columns.add(column); - } - return columns; - } - - private void setChartData(List columns) { - ColumnChartData data = new ColumnChartData(columns); - - setChartAxis(data); - - mChart.setZoomEnabled(false); - mChart.setColumnChartData(data); - } - - private void setChartAxis(ColumnChartData data) { - Axis axisX = new Axis(); - Axis axisY = new Axis().setHasLines(true); - axisX.setName("s"); - axisY.setName("s"); - data.setAxisXBottom(axisX); - data.setAxisYLeft(axisY); - } -} diff --git a/app/src/main/java/hrv/band/app/view/fragment/MeasuringFragment.java b/app/src/main/java/hrv/band/app/view/fragment/MeasuringFragment.java deleted file mode 100644 index 59e331f..0000000 --- a/app/src/main/java/hrv/band/app/view/fragment/MeasuringFragment.java +++ /dev/null @@ -1,546 +0,0 @@ -package hrv.band.app.view.fragment; - -import android.animation.Animator; -import android.animation.ObjectAnimator; -import android.app.Activity; -import android.app.AlertDialog; -import android.content.Intent; -import android.content.SharedPreferences; -import android.graphics.Point; -import android.os.Bundle; -import android.os.CountDownTimer; -import android.preference.PreferenceManager; -import android.support.design.widget.Snackbar; -import android.support.v4.app.Fragment; -import android.util.Log; -import android.util.TypedValue; -import android.view.Display; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.view.WindowManager; -import android.view.animation.LinearInterpolator; -import android.widget.ProgressBar; -import android.widget.TextView; -import android.widget.Toast; - -import org.apache.commons.lang3.ArrayUtils; - -import java.util.Date; - -import hrv.RRData; -import hrv.band.app.R; -import hrv.band.app.control.Measurement; -import hrv.band.app.devices.HRVDeviceStatus; -import hrv.band.app.devices.HRVRRDeviceListener; -import hrv.band.app.devices.HRVRRIntervalDevice; -import hrv.band.app.devices.antplus.AntPlusRRDataDevice; -import hrv.band.app.devices.msband.MSBandRRIntervalDevice; -import hrv.band.app.view.activity.HRVMeasurementActivity; -import hrv.calc.continous.HRVContinousHeartRate; -import hrv.calc.continous.HRVParameterChangedListener; -import hrv.calc.continous.HRVRRIntervalEvent; -import hrv.calc.continous.HRVRRIntervalListener; -import hrv.calc.parameter.HRVParameter; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 19.01.2017 - * - * Fragment allowing user to start measurement. - */ -public class MeasuringFragment extends Fragment implements HRVRRDeviceListener, HRVRRIntervalListener, HRVParameterChangedListener { - - /** Key value for the calculated hrv parameter. **/ - private static final String HRV_PARAMETER_ID = "HRV_PARAMETER"; - /** Key value for the selected measure device. **/ - private static final String SELECTED_DEVICE_ID = "selected_device_id"; - - /** Possible devices the user can select. **/ - private enum DeviceID {NONE, MSBAND, ANT} - - /** The shared preferences. **/ - private SharedPreferences sharedPreferences; - - /** Device to measure rr interval. **/ - private HRVRRIntervalDevice hrvRRIntervalDevice; - - /** Text view showing the current rr interval. **/ - private TextView rrStatus; - /** Text view showing the current pulse **/ - private TextView pulse; - /** Text view showing the time left of the measurement. **/ - private TextView txtMeasureTime; - /** Text view showing the status of the measurement. **/ - private TextView txtStatus; - /** Indicates the progress of the measurement. **/ - private ProgressBar progressBar; - /** The animation of the progress bar. **/ - private ObjectAnimator animation; - /** continously calculates the pulse **/ - private HRVContinousHeartRate pulseCalculator; - - /** Button to connect with the ms band. **/ - private com.github.clans.fab.FloatingActionButton connectToBandFAB; - /** Button to connect with ant+ device. **/ - private com.github.clans.fab.FloatingActionButton connectToAntPlusFAB; - /** Button to disconnect with devices. **/ - private com.github.clans.fab.FloatingActionButton disconnectDevices; - - /** The timer that shows the time to go for the measurement. **/ - private CountDownTimer countDownTimer; - - /** Root view of this fragment. **/ - private View view; - - /** - * Returns a new instance of this fragment. - * @return a new instance of this fragment. - */ - public static MeasuringFragment newInstance() { - return new MeasuringFragment(); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View rootView = inflater.inflate(R.layout.main_fragment_measure, container, false); - view = rootView.findViewById(R.id.measure_fragment); - - rrStatus = (TextView) rootView.findViewById(R.id.rrStatus); - pulse = (TextView) rootView.findViewById(R.id.pulseValue); - txtStatus = (TextView) rootView.findViewById(R.id.measure_status); - txtMeasureTime = (TextView) rootView.findViewById(R.id.measureTime); - - progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar); - - connectToBandFAB = (com.github.clans.fab.FloatingActionButton) getActivity().findViewById(R.id.connect_band_float_button); - connectToAntPlusFAB = (com.github.clans.fab.FloatingActionButton) getActivity().findViewById(R.id.connect_antplus_float_button); - disconnectDevices = (com.github.clans.fab.FloatingActionButton) getActivity().findViewById(R.id.disconnect_devices); - - sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext()); - txtMeasureTime.setText(String.valueOf(getDuration() / 1000)); - - pulseCalculator = new HRVContinousHeartRate(10); - pulseCalculator.addHRVParameterChangedListener(this); - hrvRRIntervalDevice = getDevice(DeviceID.values()[sharedPreferences.getInt(SELECTED_DEVICE_ID, 0)]); - if (hrvRRIntervalDevice != null) { - addDeviceListeners(this); - } - - MeasurementClickListener clickListener = new MeasurementClickListener(this); - - progressBar.setOnClickListener(clickListener); - if (connectToBandFAB != null) { - connectToBandFAB.setOnClickListener(clickListener); - } - if (connectToAntPlusFAB != null) { - connectToAntPlusFAB.setOnClickListener(clickListener); - } - if (disconnectDevices != null) { - disconnectDevices.setOnClickListener(clickListener); - } - - - setProgressBarSize(); - - initAnimation(); - - return rootView; - } - - /** - * Starts a countdown that shows how long the measurement will go on. - */ - private void startCountdown() { - countDownTimer = new CountDownTimer(getDuration(), 1000) { - @Override - public void onTick(long millisUntilFinished) { - txtMeasureTime.setText(String.valueOf(millisUntilFinished / 1000)); - } - @Override - public void onFinish() { - txtMeasureTime.setText(String.valueOf(getDuration())); - } - }.start(); - } - - /** - * Returns the measurement duration in ms. - * @return measurement duration in ms. - */ - private int getDuration() { - String durationPrefVal = sharedPreferences.getString("recording_length", "90"); - return Integer.parseInt(durationPrefVal) * 1000; - } - - /** - * Adds listeners to the measurement device. - * @param measuringFragment the measure fragment. - */ - private void addDeviceListeners(MeasuringFragment measuringFragment) { - hrvRRIntervalDevice.addDeviceListener(measuringFragment); - hrvRRIntervalDevice.addRRIntervalListener(measuringFragment); - hrvRRIntervalDevice.addRRIntervalListener(pulseCalculator); - } - - /** - * Returns the measurement device from the given id. - * @param id the device id from the actual measurement device. - * @return the measurement device from the given id. - */ - private HRVRRIntervalDevice getDevice(DeviceID id) { - switch (id) { - case MSBAND: return new MSBandRRIntervalDevice(getActivity()); - case ANT: return new AntPlusRRDataDevice(getContext(), getActivity()); - default: return null; - } - } - - @Override - public void onPause() { - super.onPause(); - stopMeasuring(); - } - - @Override - public void onStop() { - super.onStop(); - stopMeasuring(); - } - - /** - * Sets the progress bar size depending of the screen size. - */ - private void setProgressBarSize() { - Display mDisplay = getActivity().getWindowManager().getDefaultDisplay(); - Point size = new Point(); - mDisplay.getSize(size); - - ViewGroup.LayoutParams params = progressBar.getLayoutParams(); - int width = size.x; - if (size.x > size.y) { - width = size.y; - } - params.height = width; - params.width = width; - - setStatusTextSize(width); - - progressBar.setLayoutParams(params); - } - - /** - * Sets the font size of the RR status text view. - * @param width the width of the phone screen. - */ - private void setStatusTextSize(int width) { - float density = getResources().getDisplayMetrics().density; - rrStatus.setTextSize(TypedValue.COMPLEX_UNIT_SP, (width)/(density * 5)); - } - - /** - * Initialize the animation of the progress bar. - */ - private void initAnimation() { - animation = ObjectAnimator.ofInt (progressBar, "progress", 0, 1000); - animation.setInterpolator (new LinearInterpolator()); - animation.addListener(new ProgressBarAnimatorListener()); - } - - /** - * Stops the measuring of the device and resets the ui. - */ - public void stopMeasuring() { - if (hrvRRIntervalDevice != null && animation != null) { - hrvRRIntervalDevice.stopMeasuring(); - hrvRRIntervalDevice.clearRRIntervals(); - animation.cancel(); - resetProgress(); - } - } - - /** - * Resets the ui. - */ - private void resetProgress() { - progressBar.setProgress(progressBar.getMax()); - setConnectionButtonClickable(true); - - initAnimation(); - - updateTextView(getActivity(), rrStatus, "0,00"); - updateTextView(getActivity(), txtStatus, getResources().getString(R.string.measure_fragment_press_to_start)); - updateTextView(getActivity(), pulse, getResources().getString(R.string.measure_fragment_standard_pulse_value)); - - if (countDownTimer != null) { - countDownTimer.cancel(); - } - updateTextView(getActivity(), txtMeasureTime, String.valueOf(getDuration() / 1000)); - - getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - } - - /** - * Sets the clickable of (dis)connect buttons. - * @param clickable true if buttons should be clickable, false otherwise. - */ - private void setConnectionButtonClickable(boolean clickable) { - connectToAntPlusFAB.setClickable(clickable); - connectToBandFAB.setClickable(clickable); - disconnectDevices.setClickable(clickable); - } - - @Override - public void deviceStartedMeasurement() { - String msg = getResources().getString(R.string.msg_hold_still); - updateTextView(getActivity(), txtStatus, msg); - - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - if (animation != null) { - animation.setDuration(getDuration()); - animation.start(); - startCountdown(); - getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - } - } - }); - } - - @Override - public void deviceError(String error) { - showSnackbar(view, error); - } - - @Override - public void deviceStatusChanged(HRVDeviceStatus status) { - switch (status) { - case CONNECTING: - updateTextView(getActivity(), txtStatus, getResources().getString(R.string.msg_connecting)); - break; - case CONNECTED: - updateTextView(getActivity(), txtStatus, getResources().getString(R.string.title_activity_start_measuring)); - break; - case DISCONNECTED: - updateTextView(getActivity(), txtStatus, getResources().getString(R.string.error_band_not_paired)); - } - } - - @Override - public void newRRInterval(HRVRRIntervalEvent event) { - String format = String.format("%.2f", event.getRr()); - updateTextView(getActivity(), rrStatus, format); - } - - @Override - public void parameterChanged(HRVParameter eventArgs) { - String format = ((Integer)((int) eventArgs.getValue())).toString(); - updateTextView(getActivity(), pulse, format); - } - - /** - * Shows a snack bar with the given message in the given view. - * @param view the view the snack bar should appear. - * @param msg the message the snackbar should show. - */ - private static void showSnackbar(View view, final String msg) { - final Snackbar snackBar = Snackbar.make(view, msg, Snackbar.LENGTH_INDEFINITE); - String closeStr = snackBar.getView().getResources().getString(R.string.common_close); - - snackBar.setAction(closeStr, new View.OnClickListener() { - @Override - public void onClick(View v) { - snackBar.dismiss(); - } - }); - snackBar.show(); - } - - /** - * Updates a text view in a ui thread. - * @param activity the activity in which the thread should run. - * @param txt the text view to be set. - * @param string the string the txt should show. - */ - private static void updateTextView(Activity activity, final TextView txt, final String string) { - if (activity == null) { - return; - } - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - txt.setText(string); - } - }); - } - - /** - * Animator Listener for the progress bar. - */ - private class ProgressBarAnimatorListener implements Animator.AnimatorListener { - - @Override - public void onAnimationStart(Animator a) { - setConnectionButtonClickable(false); - } - - @Override - public void onAnimationEnd(Animator animation) { - if (hrvRRIntervalDevice == null) { - showSnackbar(view, "This should not happen..."); - } - hrvRRIntervalDevice.stopMeasuring(); - - double[] rrIntervals = ArrayUtils.toPrimitive(hrvRRIntervalDevice.getRRIntervals().toArray(new Double[0])); - - try { - Intent intent = new Intent(getContext(), HRVMeasurementActivity.class); - intent.putExtra(HRV_PARAMETER_ID, createMeasurement(rrIntervals, new Date())); - startActivity(intent); - } catch(IllegalArgumentException e) { - Log.e(e.getClass().getName(), "IllegalArgumentException", e); - new AlertDialog.Builder(getContext()) - .setTitle(R.string.error) - .setMessage(R.string.error_defective_rr_data) - .setPositiveButton(android.R.string.ok, null) - .show(); - } - - hrvRRIntervalDevice.clearRRIntervals(); - resetProgress(); - } - - @Override - public void onAnimationCancel(Animator animation) { - animation.removeAllListeners(); - } - - @Override - public void onAnimationRepeat(Animator animation) { - //is not used at the moment - } - - /** - * Calculates hrv parameter from given rr interval. - * @param rrInterval measured rr interval. - * @param time time the measurement was created. - * @return calculated hrv parameter from given rr interval. - */ - private Measurement createMeasurement(double[] rrInterval, Date time) { - //start calculation - RRData.createFromRRInterval(rrInterval, units.TimeUnit.SECOND); - - Measurement.MeasurementBuilder measurementBuilder = Measurement.from(time, rrInterval); - return measurementBuilder.build(); - } - } - - /** - * Click listener handling the clicks in this fragment. - */ - private class MeasurementClickListener implements View.OnClickListener { - - /** The measuring fragment. **/ - private final MeasuringFragment measuringFragment; - /** The activity holding the fragment. **/ - private final Activity activity; - /** The connection button containing the other buttons to (dis)connect the devices. **/ - private final com.github.clans.fab.FloatingActionMenu menuDown; - - MeasurementClickListener(MeasuringFragment measuringFragment) { - this.measuringFragment = measuringFragment; - this.activity = measuringFragment.getActivity(); - menuDown = (com.github.clans.fab.FloatingActionMenu) activity.findViewById(R.id.menu_down); - } - - @Override - public void onClick(View view) { - switch (view.getId()) { - case R.id.progressBar: - startMeasurement(); - break; - case R.id.connect_antplus_float_button: - connectToAnt(); - break; - case R.id.connect_band_float_button: - connectToMSBand(); - break; - case R.id.disconnect_devices: - disconnectDevices(); - break; - default: break; - } - } - - /** - * Starts a measurement or opens a cancel dialog if measurement already in progress. - */ - private void startMeasurement() { - if (animation.isRunning()) { - CancelMeasuringDialogFragment.newInstance().show(activity.getFragmentManager(), "dialog"); - } else { - if (hrvRRIntervalDevice != null) { - hrvRRIntervalDevice.tryStartRRIntervalMeasuring(); - } else { - Toast.makeText(activity, activity.getResources().getString(R.string.msg_select_device), Toast.LENGTH_SHORT).show(); - menuDown.open(true); - } - } - } - - /** - * Connects to ms band. - */ - private void connectToMSBand() { - setDevice(DeviceID.MSBAND); - - hrvRRIntervalDevice = new MSBandRRIntervalDevice(activity); - initDevice(); - } - - /** - * Connects to ant+ device. - */ - private void connectToAnt() { - setDevice(DeviceID.ANT); - - hrvRRIntervalDevice = new AntPlusRRDataDevice(activity.getApplicationContext(), activity); - initDevice(); - } - - /** - * Disconnects connected device. - */ - private void disconnectDevices() { - setDevice(DeviceID.NONE); - if (hrvRRIntervalDevice != null) { - hrvRRIntervalDevice.notifyDeviceStatusChanged(HRVDeviceStatus.DISCONNECTED); - hrvRRIntervalDevice = null; - } - menuDown.toggle(true); - - Toast.makeText(activity, activity.getResources().getString(R.string.msg_disconnecting), Toast.LENGTH_SHORT).show(); - } - - /** - * Initialize selected device. - */ - private void initDevice() { - addDeviceListeners(measuringFragment); - hrvRRIntervalDevice.connect(); - menuDown.toggle(true); - } - - /** - * Sets the selected device in preferences. - * @param device the device id. - */ - private void setDevice(DeviceID device) { - SharedPreferences.Editor prefsEditor = sharedPreferences.edit(); - prefsEditor.putInt(SELECTED_DEVICE_ID, device.ordinal()); - prefsEditor.apply(); - } - } -} diff --git a/app/src/main/java/hrv/band/app/view/fragment/OverviewFragment.java b/app/src/main/java/hrv/band/app/view/fragment/OverviewFragment.java deleted file mode 100644 index 8e7dbcb..0000000 --- a/app/src/main/java/hrv/band/app/view/fragment/OverviewFragment.java +++ /dev/null @@ -1,58 +0,0 @@ -package hrv.band.app.view.fragment; - -import android.content.Intent; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.ListView; - -import hrv.band.app.R; -import hrv.band.app.view.activity.HistoryActivity; -import hrv.band.app.view.adapter.HRVValue; -import hrv.band.app.view.adapter.OverviewValueAdapter; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 19.01.2017 - *

- * Fragment showing available HRV parameters. - */ -public class OverviewFragment extends Fragment { - - public static final String VALUE_TYPE = "value_type"; - - /** - * Returns a new instance of this fragment. - * - * @return a new instance of this fragment. - */ - public static OverviewFragment newInstance() { - return new OverviewFragment(); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - final View rootView = inflater.inflate(R.layout.main_fragment_overview, container, false); - ListView listView = (ListView) rootView.findViewById(R.id.overview_value_list); - final OverviewValueAdapter adapter = new OverviewValueAdapter(getActivity()); - listView.setAdapter(adapter); - - listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { - - @Override - public void onItemClick(AdapterView parent, final View view, - int position, long id) { - Intent intent = new Intent(getContext(), HistoryActivity.class); - intent.putExtra(VALUE_TYPE, HRVValue.values()[position]); - startActivity(intent); - } - - }); - - return rootView; - } -} diff --git a/app/src/main/java/hrv/band/app/view/fragment/SampleDataFragment.java b/app/src/main/java/hrv/band/app/view/fragment/SampleDataFragment.java deleted file mode 100644 index 3288545..0000000 --- a/app/src/main/java/hrv/band/app/view/fragment/SampleDataFragment.java +++ /dev/null @@ -1,128 +0,0 @@ -package hrv.band.app.view.fragment; - -import android.app.AlertDialog; -import android.app.Dialog; -import android.app.DialogFragment; -import android.content.DialogInterface; -import android.os.Bundle; -import android.view.View; -import android.widget.TextView; - -import java.util.Calendar; -import java.util.Date; -import java.util.Random; - -import hrv.band.app.control.Measurement; -import hrv.band.app.R; -import hrv.band.app.storage.IStorage; -import hrv.band.app.storage.sqlite.HRVSQLController; -import hrv.band.app.view.adapter.MeasurementCategoryAdapter; - -/** - * Copyright (c) 2017 - * Created by Thomas Czogalik on 19.01.2017 - * - * Dialog asking user to create sample data. - */ -public class SampleDataFragment extends DialogFragment { - - /** Count of rr intervals to create. **/ - private static final int RR_COUNT = 50; - /** Count of samples to create. **/ - private static final int SAMPLE_COUNT = 20; - /** Key value that indicates if the activity calling this dialog should be closed. **/ - private static final String ARG_CLOSE_VALUE = "arg_close_value"; - - /** - * Returns a new instance of this fragment. - * @param close true if calling activity should be closed after dialog closes, false otherwise. - * @return a new instance of this fragment. - */ - public static SampleDataFragment newInstance(boolean close) { - SampleDataFragment fragment = new SampleDataFragment(); - - Bundle args = new Bundle(); - args.putBoolean(ARG_CLOSE_VALUE, close); - fragment.setArguments(args); - - return fragment; - } - - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - - final View view = View.inflate(getActivity(), R.layout.dialog_simple_text, null); - - TextView textView = (TextView) view.findViewById(R.id.dialog_textview); - textView.setText(getResources().getString(R.string.sample_text)); - - builder.setView(view) - .setPositiveButton(R.string.common_create, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - for (int i = 0; i < SAMPLE_COUNT; i++) { - Calendar cal = Calendar.getInstance(); - cal.setTime(new Date()); - cal.add(Calendar.DAY_OF_MONTH, i); - - createSampleData(cal.getTime()); - - closeCallingActivity(); - } - } - }) - .setNegativeButton(R.string.common_no, new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - SampleDataFragment.this.getDialog().cancel(); - closeCallingActivity(); - } - }); - builder.setTitle(getResources().getString(R.string.sample_title)); - return builder.create(); - } - - /** - * Creates a hrv sample. - * @param date of the hrv sample. - */ - private void createSampleData(Date date) { - double[] rrValues = new double[RR_COUNT]; - - for (int i = 0; i < rrValues.length; i++) { - rrValues[i] = getRandomDouble(0.5, 1.5); - } - - Measurement.MeasurementBuilder measurementBuilder = new Measurement.MeasurementBuilder(date, rrValues); - Measurement hrv = measurementBuilder - .rating(4.4) - .category(MeasurementCategoryAdapter.MeasureCategory.SPORT) - .note("This is a sample data") - .build(); - - IStorage storage = new HRVSQLController(); - storage.saveData(getActivity(), hrv); - } - - /** - * Returns a random double within the giving range. - * @param min value of the random value. - * @param max value of the random value. - * @return a random double within the giving range. - */ - private double getRandomDouble(double min, double max) { - Random r = new Random(); - return max + (min - max) * r.nextDouble(); - } - - /** - * Closes the calling activity if the context fits. - */ - private void closeCallingActivity() { - if (getArguments().getBoolean(ARG_CLOSE_VALUE)) { - getActivity().finish(); - } - } -} diff --git a/app/src/main/java/hrv/band/app/view/fragment/SettingsFragment.java b/app/src/main/java/hrv/band/app/view/fragment/SettingsFragment.java deleted file mode 100644 index d966d56..0000000 --- a/app/src/main/java/hrv/band/app/view/fragment/SettingsFragment.java +++ /dev/null @@ -1,120 +0,0 @@ -package hrv.band.app.view.fragment; - -import android.app.Activity; -import android.app.AlertDialog; -import android.os.Bundle; -import android.preference.Preference; -import android.preference.PreferenceFragment; -import android.support.annotation.NonNull; -import android.support.design.widget.Snackbar; -import android.view.View; - -import hrv.band.app.R; -import hrv.band.app.view.presenter.ISettingsPresenter; -import hrv.band.app.view.presenter.SettingsPresenter; - -/** - * Copyright (c) 2017 - * Created by Julian on 24.01.2017. - * - * Handles the corresponding settings fragment that - * contains the view for all settings of the HRV-Band app - */ - -public class SettingsFragment extends PreferenceFragment implements ISettingsView { - - private ISettingsPresenter settingsPresenter; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.settings_fragment); - - settingsPresenter = new SettingsPresenter(this); - - addExportSetting(); - addSetRecordingLengthSetting(); - addCreateSampleSetting(); - } - - private void addExportSetting() { - Preference exportPreference = getPreferenceManager().findPreference("settings_export"); - if (exportPreference != null) { - exportPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - if (settingsPresenter.hasFileWritePermission()) { - startExportFragment(); - return true; - } else { - if (settingsPresenter.getFileWritePermission()) { - startExportFragment(); - return true; - } - } - return false; - } - }); - } - } - - private void addSetRecordingLengthSetting() { - getPreferenceManager().findPreference("recording_length").setOnPreferenceChangeListener( - new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object o) { - return settingsPresenter.isRecordLengthValid((String) o); - } - } - ); - } - - - private void addCreateSampleSetting() { - getPreferenceManager().findPreference("settings_sample").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - SampleDataFragment.newInstance(false).show(getFragmentManager(), getResources().getString(R.string.common_import)); - return false; - } - }); - } - - - @Override - public void onRequestPermissionsResult(int requestCode, - @NonNull String[] permissions, @NonNull int[] grantResults) { - settingsPresenter.onRequestPermissionsResult(requestCode, permissions, grantResults); - } - - @Override - public void startExportFragment() { - ExportFragment.newInstance().show(getFragmentManager(), getResources().getString(R.string.common_export)); - } - - @Override - public Activity getSettingsActivity() { - return getActivity(); - } - - @Override - public void showSnackbar(int messageId, View.OnClickListener clickListener) { - View view = getView(); - if (view == null) { - return; - } - - Snackbar.make(view, messageId, - Snackbar.LENGTH_INDEFINITE).setAction(R.string.common_ok, clickListener).show(); - } - - @Override - public void showAlertDialog(int titleId, int messageId) { - AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); - alert.setTitle(titleId); - alert.setMessage(messageId); - alert.setPositiveButton(android.R.string.ok, null); - alert.show(); - } - -}