top of page

The App

ThingSpeak already comes with an application ThingsView that allows visualizing the charts on the phone, however this project  aimed to design a better user-interface and addi extra functionalities. The main components of the app are:

  • To show the current heart rate as it is being measured (“Today” section of the app)

  • Ensure data protection by encrypting the app with username/password. For that a new user is created, who is given a medical ID.  Each of their details can be accessed/modified through the “Profile” page

  • Integrate an alarm system that is activated when abnormal conditions are detected. For that, the app requires the user to introduce a telephone number -preferably of the doctor, or familiar - so that an SMS is sent automatically if necessary.

The conditions to send an SMS are the following:

 

 

 

 

 

 

Next the way the app is structured and has been designed are outlined.

​

​

Mobille Application Structure :

​

Our mobile application is made of  2 activities (LoginActivity.java and MainActivity.java) whose one (MainActivity.java) which holds 4 fragments (TodayFragment.java, StatisticsFragment.java, ProfileActivity.java and SettingsActivity.java). The structure is provided below.

Captura.JPG
Capture.PNG

The receiver may get an alarm like this

 

 

 

 

 

LoginActivity

​

This activity is used to allow the user to access her/his account by providing her/his username and password.

​

MainActivity

​

It is in this activity that fragments will be shown depending on the item selected from the bottom navigation toolbar.

​

TodayFragment

​

This fragment loads the last measure stored on the channel created on ThingSpeak (IoT platform) and displays it on the smartphone screen, including the date and the hour of this measure.

​

StatisticsFragment

​

This fragment loads all the measurements stored on the channel created on ThingSpeak (IoT platform) and displays it on a chart whose the horizontal axis is the pulse and the vertical axis is the date.

​

ProfileFragment

​

This fragment contains user details (user ID, firstname, lastname, age) and an emergency contact list. User details will be used to send SMS to people from the emergency contact list. We specify that both (user details and emergency contact) have to be entered manually.

​

SettingsFragment

​

This fragment provides a switch button to allow the user to forbid or not the SMS sending.

IMG-8750.JPG

Android Studio coding explanation

LoginActivity

Extentions/Implementations :

​

public class LoginActivity extends AppCompatActivity

​

In this class, there are 3 functions :

-          protected void onCreate(@Nullable Bundle savedInstanceState)

-          public void openMainActivity()

-          protected void onStop()

​

​

What is done in it ?

​

  • Set all EditTexts, TextViews and Button

  • Set the « Log in » button behaviour :

If the provided username and password are good, open MainActivity. Otherwise, set an error message and display it in a TextView.

  • When LoginActivity is not visible anymore, delete the provided username and password.

Associed layout : activity_login.xml

​

​

​

MainActivity

​

Extensions/Implementations :

​

public class MainActivity extends AppCompatActivity implements CheckSwitchSMSState, AddContactButtonListener, UpdateDataButtonListener

 

CheckSwitchSMSState, AddContactButtonListener and UpdateDataButtonListener are interfaces to allow MainActivity to access the state of the switch button from the SettingsFragment, the « Add contact » and « Update data » from the ProfileFragment.

 

In this class, there are 18 functions :

-          protected void onCreate(Bundle savedInstanceState)

-          public boolean onNavigationItemSelected(@NonNull MenuItem item)

-          private void loadFragment(Fragment fragment)

-          protected void onResume()

-          protected void onPause()

-          protected void sendSMSMessage()

-          public void getLastMeasure()

-          public void onChanged(boolean state)

-          private void startMinuteUpdater()

-          public void receiveProfileFragmentData(Intent intent)

-          public void onClickAddContactButton(Intent intent)

-          public void onClickUpdateDataButton(Intent intent​)

-          public void saveProfileFragmentData()

-          public void loadProfileFragmentData()

-          public void checkSMSPermissions()

-          public void checkPhoneStatePermissions()

-          private void saveStateSwitchSendSMS()

-          protected void onStop()

​

What is done in it ?

  • Check the « Phone State » permission

  • Create the toolbar on the top of the screen

  • Get the last saved data from the SharedPreferences  (which means the switch state, the user profile details and the emergency contact list)

  • Set the title on the toolbar on the top on the screen

  • Load by default TodayFragment

  • Run a thread to get the last measured data every 5 seconds

  • Manage the bottom navigation toolbar to load the fragment paired with the item

  • Check if the « Add contact » and « Update data » buttons from ProfileFragment were clicked to save the new user profile details and emergency contact list in the SharedPreferences

  • Check the switch button state from SettingsFragment

  • Get ready to ask the « SMS » permission (if it is not already given) if the switch button is set on true

  • Get ready to send a SMS every minute during 3 minutes if the switch button from SettingsFragments is turned on and if the pulse rate and accelerometer data are upper or lower than specific values.

  • Get ready to increment the number of sent SMS each time that one is sent.

Associed layout : activity_main.xml

​​

​

​

​

TodayFragment

​

Extensions/Implementations :

public class TodayFragment extends Fragment

 

In this class, there are 3 functions :

-          public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)

-          public void getLastData()

-          public void setDateHour(String data)

​

What is done in it ?

 

-         Set all TextViews

-         Run a thread to get the last measured data every 5 seconds and displays them in 3 differents TextViews, respectively for the last measure, the date and the hour of its.

 

Associed layout : fragment_today_improved.xml

​

​

​

StatisticsFragment

 

Extensions/Implementations :

 

public class StatisticsFragment extends Fragment

 

In this class, there is 1 function :

-          public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) 

​

What is done in it ?

 

-         Display on the screen a progress dialog box

-         Connect to the ThingSpeak channel where pulse rate and accelerometer data are stored

-         Create the chart

-         Make the progress dialog box disappear

-         Display the chart on the screen

 

Associed layout : fragment_statistics.xml

​

​

​

ProfileFragment

 

Extensions/Implementations :

public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)

 

In this class, there are 9 functions :

-          public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

-          public void addContact(String number)

-          public void saveEmergencyContactList()

-          public void loadEmergencyContactList()

-          public void saveAddContactHelper()

-          public void loadAddContactHelper()

-          public void saveUserData()

-          public void loadUserData()

-          public void onAttach(Context context)

​

What is done in it ?

 

<>--Get the last saved data from the SharedPreferences (which means the user profile details and the emergency contact list)

  • Set listeners to make know to MainActivity if the « Add contact » or the « Update data » buttons are clicked.

  • Set the « Add contact » button behaviour :

If the button is clicked, make appear an alert dialog box to let the user provides her/his new contact. When it is done, increment the number of contacts, save this number, update the data in the emergency contact list and create and send an Intent holding all the user profile details and the emergency contact list to MainActivity. Moreover, each time that data are updated the number of sent SMS is reset to zero.

  • Set the « Update data » button behaviour :

Get the provided firstname, lastname and age, if none is empty. Otherwise, make a Toast appear to ask the user to fill all the blanks. If all is good, save the user profile details and create and send an Intent holding all the user profile details and the emergency contact list to MainActivity. Moreover, each time that data are updated the number of sent SMS is reset to zero.

 

Associed layout : fragment_profile.xml

​

​

SettingsFragment

 

Extensions/Implementations :

public class SettingsFragment extends Fragment

 

In this class, there are 4 functions :

-          public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

-          public void onResume()

-          private void saveStateSwitchSendSMS()

-          public void onAttach(Context context)

​

What is done in it ?

-         Set the Switch Button

-         Get the last saved switch button state from the SharedPreferences and set the switch in this state

-         Check every time if the switch button state changes. If it is set on true, save this state in the SharedPreferences and with a listener for the        -          CheckSwitchSMSState interface, send this state to MainActivity. If it set on false, the number of sent SMS is reset to zero.

 

Associed layout : fragment_settings.xml

​

Libraries used :

-         Volley : To make HTTP requests and receive JSON format Object

-         (Unofficial) ThingSpeakAndroid by Macro Yau : To make charts using ThingSpeak data

bottom of page