<commit_before>package hrv.band.app.view.fragment;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Point;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.LinearInterpolator;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import java.util.Date;

import hrv.RRData;
import hrv.band.app.control.HRVParameters;
import hrv.band.app.R;
import hrv.band.app.devices.HRVDeviceStatus;
import hrv.band.app.devices.HRVRRDeviceListener;
import hrv.band.app.devices.HRVRRIntervalDevice;
import hrv.band.app.devices.HRVRRIntervalEvent;
import hrv.band.app.devices.HRVRRIntervalListener;
import hrv.band.app.devices.Interval;
import hrv.band.app.devices.antplus.AntPlusRRDataDevice;
import hrv.band.app.devices.msband.MSBandRRIntervalDevice;
import hrv.band.app.view.HRVMeasurementActivity;
import hrv.calc.AllHRVIndiceCalculator;

/**
 * Copyright (c) 2017
 * Created by <NAME> on 19.01.2017
 *
 * Fragment allowing user to start measurement.
 */
public class MeasuringFragment extends Fragment implements HRVRRDeviceListener, HRVRRIntervalListener {

    /** 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 duration of the measurement. **/
    private static int duration = 90;

    /** 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 actual rr interval. **/
    private TextView rrStatus;
    /** 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;

    /** 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;

    /** 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);
        txtStatus = (TextView) rootView.findViewById(R.id.measure_status);
        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());

        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;
    }

    /**
     * Returns the measurement duration in ms.
     * @return measurement duration in ms.
     */
    private int getDuration() {
        String durationPrefVal = sharedPreferences.getString("recording_length", "90000");
        return Integer.parseInt(durationPrefVal) * 1000;
    }

    /**
     * Adds listeners to the measurement device.
     * @param measuringFragment the measure fragment.
     */
    private void addDeviceListeners(MeasuringFragment measuringFragment) {
        hrvRRIntervalDevice.addDeviceListener(measuringFragment);<commit_msg>Removed duration variable in Measuring Fragment. Fixed some issue with standard measurement time.<commit_after>package hrv.band.app.view.fragment;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Point;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.LinearInterpolator;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import java.util.Date;

import hrv.RRData;
import hrv.band.app.control.HRVParameters;
import hrv.band.app.R;
import hrv.band.app.devices.HRVDeviceStatus;
import hrv.band.app.devices.HRVRRDeviceListener;
import hrv.band.app.devices.HRVRRIntervalDevice;
import hrv.band.app.devices.HRVRRIntervalEvent;
import hrv.band.app.devices.HRVRRIntervalListener;
import hrv.band.app.devices.Interval;
import hrv.band.app.devices.antplus.AntPlusRRDataDevice;
import hrv.band.app.devices.msband.MSBandRRIntervalDevice;
import hrv.band.app.view.HRVMeasurementActivity;
import hrv.calc.AllHRVIndiceCalculator;

/**
 * Copyright (c) 2017
 * Created by <NAME> on 19.01.2017
 *
 * Fragment allowing user to start measurement.
 */
public class MeasuringFragment extends Fragment implements HRVRRDeviceListener, HRVRRIntervalListener {

    /** 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 actual rr interval. **/
    private TextView rrStatus;
    /** 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;

    /** 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;

    /** 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);
        txtStatus = (TextView) rootView.findViewById(R.id.measure_status);
        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());

        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;
    }

    /**
     * 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);
{'fraction_non_alphanumeric': 0.09371856999177106, 'fraction_numerical': 0.004114473804516778, 'mean_word_length': 3.72279792746114, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5563768', 'n_tokens_mistral': 3083, 'n_tokens_neox': 2963, 'n_words': 693}