From edb7bb6c27ccef4a70710c36c2c50f2f11daff40 Mon Sep 17 00:00:00 2001 From: George Muresan <gcm1u16@soton.ac.uk> Date: Mon, 26 Aug 2019 16:44:58 +0100 Subject: [PATCH] changes --- .idea/codeStyles/Project.xml | 116 +++++ app/src/main/AndroidManifest.xml | 12 +- .../com/uos/admin/sleepbetter/AllPages.java | 87 ++++ .../com/uos/admin/sleepbetter/B_MainMenu.java | 408 ------------------ .../admin/sleepbetter/B_WhatExperiments.java | 42 -- .../uos/admin/sleepbetter/CalendarPage.java | 60 +-- .../java/com/uos/admin/sleepbetter/Data.java | 157 ++++--- .../sleepbetter/ExperimentBroadcast.java | 43 ++ .../com/uos/admin/sleepbetter/Factors.java | 320 +++++++------- .../com/uos/admin/sleepbetter/FirstPage.java | 71 ++- .../com/uos/admin/sleepbetter/GoalDiary.java | 27 +- .../com/uos/admin/sleepbetter/MainMenu.java | 179 -------- .../java/com/uos/admin/sleepbetter/Menu.java | 408 ++++-------------- .../sleepbetter/MyCurrentExperiment.java | 72 ++++ .../com/uos/admin/sleepbetter/QFinal.java | 42 +- .../com/uos/admin/sleepbetter/QInitial.java | 58 +-- .../sleepbetter/QuestionnaireBroadcast.java | 40 ++ .../com/uos/admin/sleepbetter/Report.java | 289 ++++++------- .../com/uos/admin/sleepbetter/Settings.java | 31 ++ .../com/uos/admin/sleepbetter/Update.java | 116 +++++ .../sleepbetter/Update_Caffeine_6hours.java | 5 +- .../sleepbetter/Update_Caffeine_Empty.java | 4 +- .../sleepbetter/Update_Caffeine_limit.java | 4 +- .../sleepbetter/Update_Light_Bright.java | 4 +- .../sleepbetter/Update_Light_Glasses.java | 4 +- .../Update_Light_TurnOffBright.java | 4 +- .../sleepbetter/Update_Schedule_7hours.java | 4 +- .../sleepbetter/Update_Schedule_Midnight.java | 4 +- .../sleepbetter/Update_Schedule_Relax.java | 4 +- .../sleepbetter/Update_Schedule_SameTime.java | 4 +- .../admin/sleepbetter/WhatExperiments.java | 5 +- .../uos/admin/sleepbetter/WhatIsSleep.java | 8 +- .../res/layout/act_b_what_experiments.xml | 171 -------- .../main/res/layout/act_current_xperiment.xml | 86 ++++ app/src/main/res/layout/act_main_menu.xml | 2 +- app/src/main/res/layout/act_menu.xml | 13 + app/src/main/res/layout/act_notice.xml | 11 +- app/src/main/res/layout/act_settings.xml | 307 +++++++++++++ app/src/main/res/layout/act_welcome.xml | 31 +- app/src/main/res/values/strings.xml | 85 +--- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 +- 42 files changed, 1539 insertions(+), 1805 deletions(-) create mode 100644 .idea/codeStyles/Project.xml create mode 100644 app/src/main/java/com/uos/admin/sleepbetter/AllPages.java delete mode 100644 app/src/main/java/com/uos/admin/sleepbetter/B_MainMenu.java delete mode 100644 app/src/main/java/com/uos/admin/sleepbetter/B_WhatExperiments.java create mode 100644 app/src/main/java/com/uos/admin/sleepbetter/ExperimentBroadcast.java delete mode 100644 app/src/main/java/com/uos/admin/sleepbetter/MainMenu.java create mode 100644 app/src/main/java/com/uos/admin/sleepbetter/MyCurrentExperiment.java create mode 100644 app/src/main/java/com/uos/admin/sleepbetter/QuestionnaireBroadcast.java create mode 100644 app/src/main/java/com/uos/admin/sleepbetter/Settings.java delete mode 100644 app/src/main/res/layout/act_b_what_experiments.xml create mode 100644 app/src/main/res/layout/act_current_xperiment.xml create mode 100644 app/src/main/res/layout/act_settings.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..681f41a --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,116 @@ +<component name="ProjectCodeStyleConfiguration"> + <code_scheme name="Project" version="173"> + <codeStyleSettings language="XML"> + <indentOptions> + <option name="CONTINUATION_INDENT_SIZE" value="4" /> + </indentOptions> + <arrangement> + <rules> + <section> + <rule> + <match> + <AND> + <NAME>xmlns:android</NAME> + <XML_ATTRIBUTE /> + <XML_NAMESPACE>^$</XML_NAMESPACE> + </AND> + </match> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>xmlns:.*</NAME> + <XML_ATTRIBUTE /> + <XML_NAMESPACE>^$</XML_NAMESPACE> + </AND> + </match> + <order>BY_NAME</order> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>.*:id</NAME> + <XML_ATTRIBUTE /> + <XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE> + </AND> + </match> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>.*:name</NAME> + <XML_ATTRIBUTE /> + <XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE> + </AND> + </match> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>name</NAME> + <XML_ATTRIBUTE /> + <XML_NAMESPACE>^$</XML_NAMESPACE> + </AND> + </match> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>style</NAME> + <XML_ATTRIBUTE /> + <XML_NAMESPACE>^$</XML_NAMESPACE> + </AND> + </match> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>.*</NAME> + <XML_ATTRIBUTE /> + <XML_NAMESPACE>^$</XML_NAMESPACE> + </AND> + </match> + <order>BY_NAME</order> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>.*</NAME> + <XML_ATTRIBUTE /> + <XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE> + </AND> + </match> + <order>ANDROID_ATTRIBUTE_ORDER</order> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>.*</NAME> + <XML_ATTRIBUTE /> + <XML_NAMESPACE>.*</XML_NAMESPACE> + </AND> + </match> + <order>BY_NAME</order> + </rule> + </section> + </rules> + </arrangement> + </codeStyleSettings> + </code_scheme> +</component> \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 72a436b..afacbf8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -28,23 +28,19 @@ <!--<receiver android:name=".NotifyService"/>--> <activity android:name=".FirstPageConsent" /> - <!--receiver android:name=".MainMenu$Broadcast1" />--> - <!--receiver android:name=".MainMenu$Broadcast2" />--> + <receiver android:name=".QuestionnaireBroadcast" /> + <receiver android:name=".ExperimentBroadcast" /> <activity - android:name=".MainMenu" - android:label="@string/app_name" - android:theme="@style/AppTheme.NoActionBar"></activity> - <activity - android:name=".B_MainMenu" + android:name=".AllPages" android:label="@string/app_name" android:theme="@style/AppTheme.NoActionBar"></activity> <activity android:name=".WhatExperiments"></activity> <activity android:name=".WhatIsSleep"></activity> <activity android:name=".Notice"></activity> <activity android:name=".QInitial"></activity> - <activity android:name=".B_WhatExperiments"></activity> <activity android:name=".Demographics"></activity> + </application> </manifest> \ No newline at end of file diff --git a/app/src/main/java/com/uos/admin/sleepbetter/AllPages.java b/app/src/main/java/com/uos/admin/sleepbetter/AllPages.java new file mode 100644 index 0000000..c369e9f --- /dev/null +++ b/app/src/main/java/com/uos/admin/sleepbetter/AllPages.java @@ -0,0 +1,87 @@ +package com.uos.admin.sleepbetter; + + +import android.app.AlarmManager; +import android.app.FragmentManager; +import android.app.FragmentTransaction; +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.arch.persistence.room.Room; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.os.Build; +import android.os.Bundle; +import android.os.SystemClock; +import android.support.design.widget.TabLayout; +import android.support.v4.app.NotificationCompat; +import android.support.v4.view.ViewPager; +import android.view.View; +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.MenuItem; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.TextView; +import android.widget.Toast; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.Calendar; + +public class AllPages extends AppCompatActivity { + static Class nextclass = AllPages.class; + + + Toolbar toolbar; + TabLayout tabLayout; + ViewPager viewPager; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.act_main_menu); + + + toolbar = findViewById(R.id.toolbar_id); + setSupportActionBar(toolbar); + + + viewPager = (ViewPager) findViewById(R.id.viewPager_id); + + ViewPageAdapter adapter = new ViewPageAdapter(getSupportFragmentManager()); + + adapter.addSection(new Menu(), "Menu"); + adapter.addSection(new Factors(), "Experiments"); + adapter.addSection(new Data(), "Data"); + adapter.addSection(new GoalDiary(), "Goal Diary"); + adapter.addSection(new CalendarPage(), "Calendar"); + adapter.addSection(new Update(), "Questionnaire"); + + viewPager.setAdapter(adapter); + + tabLayout = (TabLayout) findViewById(R.id.tabLayout_id); + + tabLayout.setupWithViewPager(viewPager); + + tabLayout.getTabAt(0).setIcon(R.drawable.imageedit_32_4626940004); + tabLayout.getTabAt(1).setIcon(R.drawable.experiments); + tabLayout.getTabAt(2).setIcon(R.drawable.data); + tabLayout.getTabAt(3).setIcon(R.drawable.diaryic); + tabLayout.getTabAt(4).setIcon(R.drawable.calendar); + tabLayout.getTabAt(5).setIcon(R.drawable.pen); + + } + + +} \ No newline at end of file diff --git a/app/src/main/java/com/uos/admin/sleepbetter/B_MainMenu.java b/app/src/main/java/com/uos/admin/sleepbetter/B_MainMenu.java deleted file mode 100644 index 3605aac..0000000 --- a/app/src/main/java/com/uos/admin/sleepbetter/B_MainMenu.java +++ /dev/null @@ -1,408 +0,0 @@ -package com.uos.admin.sleepbetter; - - -import android.app.AlarmManager; -import android.app.FragmentManager; -import android.app.FragmentTransaction; -import android.app.NotificationChannel; -import android.app.NotificationManager; -import android.app.PendingIntent; -import android.arch.persistence.room.Room; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.os.Build; -import android.os.Bundle; -import android.support.design.widget.NavigationView; -import android.support.v4.app.NotificationCompat; -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.MenuItem; -import android.view.View; -import android.widget.Button; -import android.widget.ImageView; -import android.widget.TextView; -import android.widget.Toast; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Date; - -public class B_MainMenu extends AppCompatActivity { - static Class nextclass = B_MainMenu.class; - private static final String DATABASE_NAME = "user_db"; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - setContentView(R.layout.act_main_menu); - - Date c = Calendar.getInstance().getTime(); - SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy"); - final String currentDate = df.format(c); - - String startingDate = getSharedPreferences("date", MODE_PRIVATE).getString("startingDate", ""); - - Date date1 = null; - Date date2 = null; - - SimpleDateFormat dates = new SimpleDateFormat("dd-MMM-yyyy"); - - //Setting dates - try { - date1 = dates.parse(currentDate); - date2 = dates.parse(startingDate); - } catch (ParseException e) { - e.printStackTrace(); - } - - Calendar c1 = Calendar.getInstance(); - c1.setTime(date1); - - Calendar c2 = Calendar.getInstance(); - c2.setTime(date2); - - int shouldBe = c1.get(Calendar.DAY_OF_YEAR) - c2.get(Calendar.DAY_OF_YEAR); - - String expStartDate = getSharedPreferences("date", MODE_PRIVATE).getString("startExperiment", ""); - - if (shouldBe == 0 && expStartDate.equals("")) { - Toast.makeText(getApplicationContext(), "Please choose an experiment.", Toast.LENGTH_LONG).show(); - } - - //update experiments - - - String experiments = getSharedPreferences("experiments", MODE_PRIVATE).getString("experiments", ""); - - //+1 to include dy 0 - String[] experimentsArray = experiments.split("gcm"); - - if (shouldBe > experimentsArray.length){ - String currentExperiment = getSharedPreferences("name", MODE_PRIVATE).getString("experiment", "nothing"); - - ArrayList<String> experimentsArrayList = new ArrayList<String>(Arrays.asList(experimentsArray)); - for (int i=0; i< (shouldBe - experimentsArray.length); i++){ - experimentsArrayList.add(currentExperiment + "."); - } - - experimentsArray = experimentsArrayList.toArray(experimentsArray); - - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < experimentsArray.length; i++) { - sb.append(experimentsArray[i]).append("gcm"); - } - getSharedPreferences("experiments", MODE_PRIVATE).edit().putString("experiments", sb.toString()).apply(); - - } - - //context.getSharedPreferences("questionnaire", MODE_PRIVATE).edit().putBoolean("completed", false).apply(); - //context.getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE).edit().putBoolean("locked", true).apply(); - - //scoatem variabila days si verificam: daca se imparte la 5, si nu e locked, - ImageView imageView = findViewById(R.id.imageView2); - /* - imageView.setImageResource(R.drawable.sleep); - - - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); - setSupportActionBar(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); - - View headerView = navigationView.getHeaderView(0); - TextView navUsername = (TextView) headerView.findViewById(R.id.nameOfUser); - - String name = getSharedPreferences("name", MODE_PRIVATE).getString("username", "nothing"); - navUsername.setText(name); -*/ - //NOTIFICATION DEMO - this.createNotificationChannel(); - this.setNotifications(); -///END NOTIFICATIONs - - Button button1 = (Button) findViewById(R.id.whatSleep); - - button1.setOnClickListener(new View.OnClickListener() { - - public void onClick(View v) { - - goToWhatIsSleep(); - - } - - }); - - Button button3 = (Button) findViewById(R.id.WhatExperiments); - - button3.setOnClickListener(new View.OnClickListener() { - - public void onClick(View v) { - - goToWhatExperiments(); - - } - - }); - - - TextView remainedDaysText = (TextView) findViewById(R.id.youHave); - - if (expStartDate.equals("")){ - remainedDaysText.setText("Please choose your experiment in the Experiments section."); - } else { - Date date3 = null; - - //Setting dates - try { - date3 = dates.parse(expStartDate); - } catch (ParseException e) { - e.printStackTrace(); - } - - Calendar c3 = Calendar.getInstance(); - c3.setTime(date3); - - int experimentDaysDifference = c1.get(Calendar.DAY_OF_YEAR) - c3.get(Calendar.DAY_OF_YEAR); - - int difference = 5 - experimentDaysDifference; - - - remainedDaysText.setText("You have " + difference + " days left of the current experiment."); - - - if (expStartDate.equals(currentDate)) { - remainedDaysText.setText("You have 5 days left of the current experiment."); - } else if (difference < 5 && difference != 0){ - remainedDaysText.setText(difference + " days left of the current experiment."); - } else { - remainedDaysText.setText(difference + " days left of the current experiment. When available, change your experiment in the Experiments section."); - } - - } - - - String previousExperimentStartDate = getSharedPreferences("date", MODE_PRIVATE).getString("startExperiment", ""); - - Date date3 = null; - Date date4 = null; - - if (previousExperimentStartDate.equals("")){ - previousExperimentStartDate = currentDate; - } - //Setting dates - try { - date3 = dates.parse(currentDate); - date4 = dates.parse(previousExperimentStartDate); - } catch (ParseException e) { - e.printStackTrace(); - } - - - Calendar c3 = Calendar.getInstance(); - c3.setTime(date3); - - Calendar c4 = Calendar.getInstance(); - c4.setTime(date4); - - int differenceBetweenOldExperimentAndCurrent = c3.get(Calendar.DAY_OF_YEAR) - c4.get(Calendar.DAY_OF_YEAR); - - if (differenceBetweenOldExperimentAndCurrent != 0){ - getSharedPreferences("expB", MODE_PRIVATE).edit().putString("pickedB", "pickedB").apply(); - } - - } - - private void goToWhatIsSleep() { - Intent intent = new Intent(this, WhatIsSleep.class); - - startActivity(intent); - - } - - private void goToWhatExperiments() { - Intent intent = new Intent(this, B_WhatExperiments.class); - - startActivity(intent); - - } -/* - @Override - public void onBackPressed() { - DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); - if (drawer.isDrawerOpen(GravityCompat.START)) { - drawer.closeDrawer(GravityCompat.START); - } else { - - int count = getFragmentManager().getBackStackEntryCount(); - - if (count == 0) { - System.out.println("returns"); - moveTaskToBack(true); - } else { - getFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); - } - } - } -*/ - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. - int id = item.getItemId(); - - //noinspection SimplifiableIfStatement - - return super.onOptionsItemSelected(item); - } -/* - @SuppressWarnings("StatementWithEmptyBody") - @Override - public boolean onNavigationItemSelected(MenuItem item) { - // Handle navigation view item clicks here. - int id = item.getItemId(); - FragmentManager fragmentManager = getFragmentManager(); - FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); - - if (id == R.id.nav_factors) { - fragmentTransaction.replace(R.id.content_frame, new Factors()); - } - - fragmentTransaction.addToBackStack(null); - fragmentTransaction.commit(); - getFragmentManager().executePendingTransactions(); - - DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); - drawer.closeDrawer(GravityCompat.START); - return true; - } -*/ - private void createNotificationChannel() { - // Create the NotificationChannel, but only on API 26+ because - // the NotificationChannel class is new and not in the support library - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - CharSequence name = "reminder"; - int importance = NotificationManager.IMPORTANCE_DEFAULT; - NotificationChannel channel = new NotificationChannel("13", name, importance); - // Register the channel with the system; you can't change the importance - // or other notification behaviors after this - NotificationManager notificationManager = getSystemService(NotificationManager.class); - notificationManager.createNotificationChannel(channel); - } - } - - private void setAlarmManager(int hour, int minute, final String title, final String message) { - - getSharedPreferences("notification", MODE_PRIVATE).getString("title", "nothing"); - getSharedPreferences("notification", MODE_PRIVATE).edit().putString("title", title).apply(); - getSharedPreferences("notification", MODE_PRIVATE).getString("message", "nothing"); - getSharedPreferences("notification", MODE_PRIVATE).edit().putString("message", message).apply(); - - Calendar calendar = Calendar.getInstance(); - calendar.set(Calendar.HOUR_OF_DAY, hour); - calendar.set(Calendar.MINUTE, minute); - calendar.set(Calendar.SECOND, 0); - - if (Calendar.getInstance().after(calendar)) { - calendar.add(Calendar.DAY_OF_MONTH, 1); - } - - Intent intent1 = new Intent(B_MainMenu.this, Broadcast1.class); - PendingIntent pendingIntent = PendingIntent.getBroadcast(B_MainMenu.this, 0, intent1, 0); - AlarmManager am = (AlarmManager) B_MainMenu.this.getSystemService(B_MainMenu.this.ALARM_SERVICE); - am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent); - } - - - //produce the required notifications - private void setNotifications() { - int experiment = getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE).getInt("KEY_SAVED_RADIO_BUTTON_INDEX", 0); - - switch (experiment) { - case 1: //increase bright light exposure - setAlarmManager(12, 0, "Remember:", "Stay out in the sun at least half an hour today!"); - break; - case 2: //wear glasses that block blue light during the night - setAlarmManager(12, 30, "Remember:", "Use the \"f.lux\" app!"); - break; - case 3: // turn off any bright lights 2 hours before going to bed - setAlarmManager(19, 30, "Going to bed soon?", "Do not forget to turn off your light with 2 hours before bed!"); - break; - case 5: // Do not drink caffeine within 6 hours - setAlarmManager(15, 0, "Remember:", "Do not drink caffeine with 6 hours before going to sleep!"); - break; - case 6: // Limit yourself to 4 cups of coffees per day; 10 canss of - setAlarmManager(16, 24, "Remember:", "Limit yourself to 4 cups of coffee per day/10 cans of soda or 2 energy drinks!"); - break; - case 7: //Do not drink empty stomach - setAlarmManager(8, 0, "Remember:", "Try not to drink caffeine on an empty stomach!"); - break; - case 9://Usually get up at the same time everyday, even on weekends - setAlarmManager(18, 30, "Remember:", "Do not forget! Go to bed and wake up at the same time as yesterday!"); - break; - case 10: // Sleep no lesss than 7 hours per night - System.out.println("should be"); - setAlarmManager(19, 50, "Remember:", "Sleep no less than 7 hours per night!"); - break; - case 11: //DO not go to bed unless you are tired. If you are not - setAlarmManager(20, 00, "Remember", "Do not go to bed unless you are tired. Read a book, take a bath, stretch or drink tea to relax!"); - break; - case 12: //Go to sleep at 22:30 PM the latest - setAlarmManager(21, 00, "Remember:", "Go to sleep at 10:30 PM the latest!"); - break; - } - - } - - public static class Broadcast1 extends BroadcastReceiver { - @Override - public void onReceive(Context context, Intent intent) { - - String titleM = context.getSharedPreferences("notification", MODE_PRIVATE).getString("title", "nothing"); - String messageM = context.getSharedPreferences("notification", MODE_PRIVATE).getString("message", "nothing"); - - - long when = System.currentTimeMillis(); - NotificationManager notificationManager = (NotificationManager) context - .getSystemService(Context.NOTIFICATION_SERVICE); - - Intent notificationIntent = new Intent(context, nextclass); - notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - - PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, - notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); - - - // Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); - - NotificationCompat.Builder mNotifyBuilder = new NotificationCompat.Builder(context, "13") - .setSmallIcon(R.drawable.data) - .setContentTitle(titleM) - .setStyle(new NotificationCompat.BigTextStyle() - .bigText(messageM)) - .setContentText(messageM) - .setAutoCancel(true).setWhen(when) - .setContentIntent(pendingIntent); - notificationManager.notify(13, mNotifyBuilder.build()); -// - } - } - -} \ No newline at end of file diff --git a/app/src/main/java/com/uos/admin/sleepbetter/B_WhatExperiments.java b/app/src/main/java/com/uos/admin/sleepbetter/B_WhatExperiments.java deleted file mode 100644 index 6253cad..0000000 --- a/app/src/main/java/com/uos/admin/sleepbetter/B_WhatExperiments.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.uos.admin.sleepbetter; - -import android.content.Intent; -import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; -import android.view.View; -import android.widget.Button; -import android.widget.ImageView; - -public class B_WhatExperiments extends AppCompatActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.act_b_what_experiments); - - ImageView imageView = findViewById(R.id.imageView23); - imageView.setImageResource(R.drawable.data); - - - Button button = (Button) findViewById(R.id.back); - - button.setOnClickListener(new View.OnClickListener() { - - public void onClick(View v) { - - goToThirdActivity(); - - } - - }); - } - - private void goToThirdActivity() { - - - Intent intent = new Intent(this, B_MainMenu.class); - - startActivity(intent); - - } -} diff --git a/app/src/main/java/com/uos/admin/sleepbetter/CalendarPage.java b/app/src/main/java/com/uos/admin/sleepbetter/CalendarPage.java index 2eaa650..9716ecc 100644 --- a/app/src/main/java/com/uos/admin/sleepbetter/CalendarPage.java +++ b/app/src/main/java/com/uos/admin/sleepbetter/CalendarPage.java @@ -36,20 +36,23 @@ public class CalendarPage extends Fragment { helpView = inflater.inflate(R.layout.act_calendar, container, false); -/* - HomeCollection.date_collection_arr = new ArrayList<HomeCollection>(); - HomeCollection.date_collection_arr.add(new HomeCollection("2017-07-08", "Diwali", "Holiday", "this is holiday")); - HomeCollection.date_collection_arr.add(new HomeCollection("2017-07-08", "Holi", "Holiday", "this is holiday")); - HomeCollection.date_collection_arr.add(new HomeCollection("2017-07-08", "Statehood Day", "Holiday", "this is holiday")); - HomeCollection.date_collection_arr.add(new HomeCollection("2017-08-08", "Republic Unian", "Holiday", "this is holiday")); - HomeCollection.date_collection_arr.add(new HomeCollection("2017-07-09", "ABC", "Holiday", "this is holiday")); - HomeCollection.date_collection_arr.add(new HomeCollection("2017-06-15", "demo", "Holiday", "this is holiday")); - HomeCollection.date_collection_arr.add(new HomeCollection("2017-09-26", "weekly off", "Holiday", "this is holiday")); - HomeCollection.date_collection_arr.add(new HomeCollection("2018-01-08", "Events", "Holiday", "this is holiday")); - HomeCollection.date_collection_arr.add(new HomeCollection("2018-01-16", "Dasahara", "Holiday", "this is holiday")); - HomeCollection.date_collection_arr.add(new HomeCollection("2018-02-09", "Christmas", "Holiday", "this is holiday")); - -*/ + return helpView; + } + + private boolean isViewShown = false; + + @Override + public void setUserVisibleHint(boolean isVisibleToUser) { + super.setUserVisibleHint(isVisibleToUser); + if (getView() != null) { + isViewShown = true; + loadPageDataProcessing(); + } else { + isViewShown = false; + } + } + + public void loadPageDataProcessing() { Date c = Calendar.getInstance().getTime(); SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy"); @@ -96,7 +99,7 @@ public class CalendarPage extends Fragment { for (int i = 0; i <= shouldBe - 1; i++) { Date d1 = null; - try { + try { d1=new SimpleDateFormat("dd-MMM-yyyy").parse(dayForLoop); } catch (ParseException e) { e.printStackTrace(); @@ -105,13 +108,8 @@ public class CalendarPage extends Fragment { String dateToAdd = changer.format(d1); - System.out.println("CHECKKKKKKKKKK"); - System.out.println(experimentsArray.length); - System.out.println(moods.length); - System.out.println(dateToAdd); HomeCollection.date_collection_arr.add(new HomeCollection(dateToAdd, experimentsArray[i], moods[i], diaries[i])); - try { cal.setTime(df.parse(dayForLoop)); } catch (ParseException e) { @@ -172,28 +170,12 @@ public class CalendarPage extends Fragment { }); - return helpView; } @Override public void onResume() { super.onResume(); -/* - HomeCollection.date_collection_arr = new ArrayList<HomeCollection>(); - HomeCollection.date_collection_arr.add(new HomeCollection("2017-07-08", "Diwali", "Holiday", "this is holiday")); - HomeCollection.date_collection_arr.add(new HomeCollection("2017-07-08", "Holi", "Holiday", "this is holiday")); - HomeCollection.date_collection_arr.add(new HomeCollection("2017-07-08", "Statehood Day", "Holiday", "this is holiday")); - HomeCollection.date_collection_arr.add(new HomeCollection("2017-08-08", "Republic Unian", "Holiday", "this is holiday")); - HomeCollection.date_collection_arr.add(new HomeCollection("2017-07-09", "ABC", "Holiday", "this is holiday")); - HomeCollection.date_collection_arr.add(new HomeCollection("2017-06-15", "demo", "Holiday", "this is holiday")); - HomeCollection.date_collection_arr.add(new HomeCollection("2017-09-26", "weekly off", "Holiday", "this is holiday")); - HomeCollection.date_collection_arr.add(new HomeCollection("2018-01-08", "Events", "Holiday", "this is holiday")); - HomeCollection.date_collection_arr.add(new HomeCollection("2018-01-16", "Dasahara", "Holiday", "this is holiday")); - HomeCollection.date_collection_arr.add(new HomeCollection("2018-02-09", "Christmas", "Holiday", "this is holiday")); - -*/ - Date c = Calendar.getInstance().getTime(); SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy"); final String currentDate = df.format(c); @@ -248,10 +230,6 @@ public class CalendarPage extends Fragment { String dateToAdd = changer.format(d1); - System.out.println("CHECKKKKKKKKKK"); - System.out.println(experimentsArray.length); - System.out.println(moods.length); - System.out.println(dateToAdd); HomeCollection.date_collection_arr.add(new HomeCollection(dateToAdd, experimentsArray[i], moods[i], diaries[i])); @@ -339,4 +317,6 @@ public class CalendarPage extends Fragment { hwAdapter.notifyDataSetChanged(); tv_month.setText(android.text.format.DateFormat.format("MMMM yyyy", cal_month)); } + + } \ No newline at end of file diff --git a/app/src/main/java/com/uos/admin/sleepbetter/Data.java b/app/src/main/java/com/uos/admin/sleepbetter/Data.java index 3101488..19d0a84 100644 --- a/app/src/main/java/com/uos/admin/sleepbetter/Data.java +++ b/app/src/main/java/com/uos/admin/sleepbetter/Data.java @@ -5,21 +5,18 @@ import android.app.Dialog; import android.arch.persistence.room.Room; import android.content.Context; import android.content.DialogInterface; -import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Color; import android.os.Bundle; import android.preference.PreferenceManager; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; -import android.widget.ImageView; import android.widget.Spinner; import android.widget.TextView; @@ -27,17 +24,11 @@ import com.jjoe64.graphview.GraphView; import com.jjoe64.graphview.series.DataPoint; import com.jjoe64.graphview.series.LineGraphSeries; -import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Date; import java.util.Iterator; import java.util.List; import android.support.v4.app.DialogFragment; -import static android.content.Context.MODE_PRIVATE; - public class Data extends Fragment implements AdapterView.OnItemSelectedListener { private UserDatabase userDatabase; private static final String DATABASE_NAME = "user_db"; @@ -48,9 +39,6 @@ public class Data extends Fragment implements AdapterView.OnItemSelectedListener @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { dataView = inflater.inflate(R.layout.act_data, container, false); - ImageView imageView1 = (ImageView) dataView.findViewById(R.id.imageView28); - - imageView1.setImageResource(R.drawable.data); Button info1 = (Button) dataView.findViewById(R.id.infoRatings); info1.setOnClickListener(new View.OnClickListener() { @@ -82,6 +70,25 @@ public class Data extends Fragment implements AdapterView.OnItemSelectedListener } }); + return dataView; + } + + + private boolean isViewShown = false; + + @Override + public void setUserVisibleHint(boolean isVisibleToUser) { + super.setUserVisibleHint(isVisibleToUser); + if (getView() != null) { + isViewShown = true; + loadPageDataProcessing(); + } else { + isViewShown = false; + } + } + + public void loadPageDataProcessing() { + new Thread(new Runnable() { @Override @@ -146,10 +153,6 @@ public class Data extends Fragment implements AdapterView.OnItemSelectedListener GraphView graph2 = (GraphView) dataView.findViewById(R.id.shortMood); DataPoint[] dp2; - //diferit pt ca luam doar de la structuri de 5 - - - if (userDatabase.daoAccess().fetchMoods().size() > 1) { int sizeOfSecondGraph = 0; @@ -171,8 +174,6 @@ public class Data extends Fragment implements AdapterView.OnItemSelectedListener dp2 = new DataPoint[sizeOfSecondGraph]; - //cum schimb - i=0; int k=0; Iterator it = numberOfGoodMoods.iterator(); @@ -245,73 +246,16 @@ public class Data extends Fragment implements AdapterView.OnItemSelectedListener updateAllTexts(); spinner = (Spinner) dataView.findViewById(R.id.spinner); -// Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity().getApplicationContext(), R.array.targetGraph, android.R.layout.simple_spinner_item); -// Specify the layout to use when the list of choices appears adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); -// Apply the adapter to the spinner + spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(this); - - - return dataView; } - public static class InfoOneDialog extends DialogFragment { - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - builder.setMessage("This section shows your state as reported in yesterday's questionnaire. The overall mood value was computed based on all of your answers. If the values show -1, it means you forgot to fill in the questionnaire."); - builder.setNegativeButton("OK", new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - dialog.dismiss(); - } - }); - return builder.create(); - } - } - public static class InfoTwoDialog extends DialogFragment { - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - builder.setMessage("This section aims to recommend the fields that could be improved since yesterday's questionnaire. As higher values are associated with worse feelings, this section highlights all the attributes rated 3+. Bear in mind that if you haven't completed yesterday's questionnaire, this section will be empty."); - builder.setNegativeButton("OK", new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - dialog.dismiss(); - } - }); - return builder.create(); - } - } - public static class InfoThreeDialog extends DialogFragment { - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - builder.setMessage("This section displays 3 graphs based on your progress while using the app. First graph shows your overall progress in time while using SleepBetter. Second graph shows the same progress but for only a duration of 5 days- the current running experiment. For the third graph you are able to choose which attribute's progress you want to view during the time you used SleepBetter. \"Lower is better\" means a lower value is desirable, as it shows a better, improved state."); - builder.setNegativeButton("OK", new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - dialog.dismiss(); - } - }); - return builder.create(); - } - } - public static class InfoFourDialog extends DialogFragment { - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - builder.setMessage("For this graph you are able to choose which attribute's progress you want to view during the time you used SleepBetter. \\\"Lower is better\\\" means a lower value is desirable, as it shows a better, improved state."); - builder.setNegativeButton("OK", new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - dialog.dismiss(); - } - }); - return builder.create(); - } - } private int sizeOfMoods(ArrayList<Double> integers) { @@ -395,11 +339,6 @@ public class Data extends Fragment implements AdapterView.OnItemSelectedListener graph.removeAllSeries(); ArrayList<Double> numberOfGoodMoods = (ArrayList<Double>) userDatabase.daoAccess().fetchMoods(); - int sizeMoods = sizeOfMoods(numberOfGoodMoods); - - - System.out.println("DATAAAAAAAAAAAAAAAAAAAAa"); - System.out.println(sizeMoods); int sizeToGraph = 0; @@ -478,9 +417,61 @@ public class Data extends Fragment implements AdapterView.OnItemSelectedListener }).start(); } - @Override - public void onNothingSelected(AdapterView<?> parent) { + public static class InfoOneDialog extends DialogFragment { + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setMessage("This section shows your state as reported in yesterday's questionnaire. The overall mood value was computed based on all of your answers. If the values show -1, it means you forgot to fill in the questionnaire."); + builder.setNegativeButton("OK", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.dismiss(); + } + }); + return builder.create(); + } + } + public static class InfoTwoDialog extends DialogFragment { + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setMessage("This section aims to recommend the fields that could be improved since yesterday's questionnaire. As higher values are associated with worse feelings, this section highlights all the attributes rated 3+. Bear in mind that if you haven't completed yesterday's questionnaire, this section will be empty."); + builder.setNegativeButton("OK", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.dismiss(); + } + }); + return builder.create(); + } + } + public static class InfoThreeDialog extends DialogFragment { + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setMessage("This section displays 3 graphs based on your progress while using the app. First graph shows your overall progress in time while using SleepBetter. Second graph shows the same progress but for only a duration of 5 days- the current running experiment. For the third graph you are able to choose which attribute's progress you want to view during the time you used SleepBetter. \"Lower is better\" means a lower value is desirable, as it shows a better, improved state."); + builder.setNegativeButton("OK", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.dismiss(); + } + }); + return builder.create(); + } + } + public static class InfoFourDialog extends DialogFragment { + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setMessage("For this graph you are able to choose which attribute's progress you want to view during the time you used SleepBetter. \\\"Lower is better\\\" means a lower value is desirable, as it shows a better, improved state."); + builder.setNegativeButton("OK", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.dismiss(); + } + }); + return builder.create(); + } + } + @Override + public void onNothingSelected(AdapterView<?> adapterView) { } } \ No newline at end of file diff --git a/app/src/main/java/com/uos/admin/sleepbetter/ExperimentBroadcast.java b/app/src/main/java/com/uos/admin/sleepbetter/ExperimentBroadcast.java new file mode 100644 index 0000000..f0b29c4 --- /dev/null +++ b/app/src/main/java/com/uos/admin/sleepbetter/ExperimentBroadcast.java @@ -0,0 +1,43 @@ +package com.uos.admin.sleepbetter; + +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.support.v4.app.NotificationCompat; + +import static android.content.Context.MODE_PRIVATE; +import static com.uos.admin.sleepbetter.AllPages.nextclass; + +public class ExperimentBroadcast extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + + String messageM = context.getSharedPreferences("notification", MODE_PRIVATE).getString("message", "nothing"); + + + long when = System.currentTimeMillis(); + NotificationManager notificationManager = (NotificationManager) context + .getSystemService(Context.NOTIFICATION_SERVICE); + + Intent notificationIntent = new Intent(context, nextclass); + notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + + PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, + notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); + + + NotificationCompat.Builder mNotifyBuilder = new NotificationCompat.Builder(context, "13") + .setSmallIcon(R.drawable.pillow) + .setContentTitle("Experiment reminder") + .setStyle(new NotificationCompat.BigTextStyle() + .bigText(messageM)) + .setContentText(messageM) + .setAutoCancel(false).setWhen(when) + .setOngoing(true) + .setContentIntent(pendingIntent); + notificationManager.notify(13, mNotifyBuilder.build()); + + } + } \ No newline at end of file diff --git a/app/src/main/java/com/uos/admin/sleepbetter/Factors.java b/app/src/main/java/com/uos/admin/sleepbetter/Factors.java index 503a8a7..384d030 100644 --- a/app/src/main/java/com/uos/admin/sleepbetter/Factors.java +++ b/app/src/main/java/com/uos/admin/sleepbetter/Factors.java @@ -1,10 +1,15 @@ package com.uos.admin.sleepbetter; +import android.app.AlarmManager; import android.app.AlertDialog; import android.app.Dialog; +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.app.PendingIntent; import android.arch.persistence.room.Room; import android.content.DialogInterface; import android.content.Intent; +import android.os.Build; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.DialogFragment; @@ -32,24 +37,40 @@ public class Factors extends Fragment { View factorsView; private static RadioGroup radioGroup; - private boolean shouldBlockTouches = false; - - private static final String DATABASE_NAME = "user_db"; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { factorsView = inflater.inflate(R.layout.act_experiments, container, false); - Button button2 = (Button) factorsView.findViewById(R.id.submit); - /* button2.setOnClickListener(new View.OnClickListener() { + button2.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { submitExperiment(); } }); -*/ + return factorsView; + } + + + private boolean isViewShown = false; + + @Override + public void setUserVisibleHint(boolean isVisibleToUser) { + super.setUserVisibleHint(isVisibleToUser); + if (getView() != null) { + isViewShown = true; + loadPageDataProcessing(); + } else { + isViewShown = false; + } + } + + public void loadPageDataProcessing(){ + + + String experiment = getActivity().getApplicationContext().getSharedPreferences("name", MODE_PRIVATE).getString("experiment", "nothing"); int savedRadioIndex = getActivity().getApplicationContext().getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE).getInt("KEY_SAVED_RADIO_BUTTON_INDEX", 0); @@ -70,112 +91,85 @@ public class Factors extends Fragment { RadioButton rb =(RadioButton) factorsView.findViewById(checkedId); if (rb.getText().equals(getString(R.string.firstLight))){ getActivity().getSharedPreferences("name", MODE_PRIVATE).edit().putString("experiment", getString(R.string.firstLight)).apply(); - SavePreferences("KEY_SAVED_RADIO_BUTTON_INDEX", 1); + getActivity().getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE).edit().putInt("KEY_SAVED_RADIO_BUTTON_INDEX", 1).apply(); } else if (rb.getText().equals(getString(R.string.secondLight))){ getActivity().getSharedPreferences("name", MODE_PRIVATE).edit().putString("experiment", getString(R.string.secondLight)).apply(); - SavePreferences("KEY_SAVED_RADIO_BUTTON_INDEX", 2); + getActivity().getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE).edit().putInt("KEY_SAVED_RADIO_BUTTON_INDEX", 2).apply(); } else if (rb.getText().equals(getString(R.string.thirdLight))){ getActivity().getSharedPreferences("name", MODE_PRIVATE).edit().putString("experiment", getString(R.string.thirdLight)).apply(); - SavePreferences("KEY_SAVED_RADIO_BUTTON_INDEX", 3); + getActivity().getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE).edit().putInt("KEY_SAVED_RADIO_BUTTON_INDEX", 3).apply(); } else if (rb.getText().equals(getString(R.string.firstCaffeine))){ getActivity().getSharedPreferences("name", MODE_PRIVATE).edit().putString("experiment", getString(R.string.firstCaffeine)).apply(); - SavePreferences("KEY_SAVED_RADIO_BUTTON_INDEX", 5); + getActivity().getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE).edit().putInt("KEY_SAVED_RADIO_BUTTON_INDEX", 5).apply(); } else if (rb.getText().equals(getString(R.string.secondCaffeine))){ getActivity().getSharedPreferences("name", MODE_PRIVATE).edit().putString("experiment", getString(R.string.secondCaffeine)).apply(); - SavePreferences("KEY_SAVED_RADIO_BUTTON_INDEX", 6); + getActivity().getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE).edit().putInt("KEY_SAVED_RADIO_BUTTON_INDEX", 6).apply(); } else if (rb.getText().equals(getString(R.string.thirdCaffeine))){ getActivity().getSharedPreferences("name", MODE_PRIVATE).edit().putString("experiment", getString(R.string.thirdCaffeine)).apply(); - SavePreferences("KEY_SAVED_RADIO_BUTTON_INDEX", 7); + getActivity().getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE).edit().putInt("KEY_SAVED_RADIO_BUTTON_INDEX", 7).apply(); } else if (rb.getText().equals(getString(R.string.firstSchedule))){ getActivity().getSharedPreferences("name", MODE_PRIVATE).edit().putString("experiment", getString(R.string.firstSchedule)).apply(); - SavePreferences("KEY_SAVED_RADIO_BUTTON_INDEX", 9); + getActivity().getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE).edit().putInt("KEY_SAVED_RADIO_BUTTON_INDEX", 9).apply(); } else if (rb.getText().equals(getString(R.string.secondSchedule))){ getActivity().getSharedPreferences("name", MODE_PRIVATE).edit().putString("experiment", getString(R.string.secondSchedule)).apply(); - SavePreferences("KEY_SAVED_RADIO_BUTTON_INDEX", 10); + getActivity().getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE).edit().putInt("KEY_SAVED_RADIO_BUTTON_INDEX", 10).apply(); } else if (rb.getText().equals(getString(R.string.thirdSchedule))){ getActivity().getSharedPreferences("name", MODE_PRIVATE).edit().putString("experiment", getString(R.string.thirdSchedule)).apply(); - SavePreferences("KEY_SAVED_RADIO_BUTTON_INDEX", 11); + getActivity().getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE).edit().putInt("KEY_SAVED_RADIO_BUTTON_INDEX", 11).apply(); } else if (rb.getText().equals(getString(R.string.fourthSchedule))){ getActivity().getSharedPreferences("name", MODE_PRIVATE).edit().putString("experiment", getString(R.string.fourthSchedule)).apply(); - SavePreferences("KEY_SAVED_RADIO_BUTTON_INDEX", 12); + getActivity().getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE).edit().putInt("KEY_SAVED_RADIO_BUTTON_INDEX", 12).apply(); } } }); - Date c = Calendar.getInstance().getTime(); - SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy"); - final String currentDate = df.format(c); - - String previousExperimentStartDate = getActivity().getSharedPreferences("date", MODE_PRIVATE).getString("startExperiment", ""); - String studyStartDate = getActivity().getSharedPreferences("date", MODE_PRIVATE).getString("startingDate", ""); + Date c = Calendar.getInstance().getTime(); + SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy"); + final String currentDate = df.format(c); + String previousExperimentStartDate = getActivity().getSharedPreferences("date", MODE_PRIVATE).getString("startExperiment", ""); - Calendar calendar1 = Calendar.getInstance(); - SimpleDateFormat formatter1 = new SimpleDateFormat("HH"); - String currentHour = formatter1.format(calendar1.getTime()); - + Calendar calendar1 = Calendar.getInstance(); + SimpleDateFormat formatter1 = new SimpleDateFormat("HH"); + String currentHour = formatter1.format(calendar1.getTime()); String experiments = getActivity().getApplicationContext().getSharedPreferences("experiments", MODE_PRIVATE).getString("experiments", ""); String[] experimentsArray = experiments.split("gcm"); - int loggedIn = experimentsArray.length; - Date date1 = null; - Date date2 = null; - - SimpleDateFormat dates = new SimpleDateFormat("dd-MMM-yyyy"); - - if (previousExperimentStartDate.equals("")){ - previousExperimentStartDate = currentDate; - } - //Setting dates - try { - date1 = dates.parse(currentDate); - date2 = dates.parse(previousExperimentStartDate); - } catch (ParseException e) { - e.printStackTrace(); - } - - - Calendar c1 = Calendar.getInstance(); - c1.setTime(date1); - - Calendar c2 = Calendar.getInstance(); - c2.setTime(date2); - - int differenceBetweenOldExperimentAndCurrent = c1.get(Calendar.DAY_OF_YEAR) - c2.get(Calendar.DAY_OF_YEAR); - - - - String participantID = getActivity().getApplicationContext().getSharedPreferences("name", MODE_PRIVATE).getString("participantID", "nothing"); + int loggedIn = experimentsArray.length; + Date date1 = null; + Date date2 = null; + SimpleDateFormat dates = new SimpleDateFormat("dd-MMM-yyyy"); + if (previousExperimentStartDate.equals("")){ + previousExperimentStartDate = currentDate; + } + //Setting dates + try { + date1 = dates.parse(currentDate); + date2 = dates.parse(previousExperimentStartDate); + } catch (ParseException e) { + e.printStackTrace(); + } - if (participantID.contains("B") || participantID.contains("b")){ - if (differenceBetweenOldExperimentAndCurrent % 5 != 0){ - for (int i = 0; i < radioGroup.getChildCount(); i++) { - radioGroup.getChildAt(i).setEnabled(false); - } - Toast.makeText(getActivity().getApplicationContext(), "You are not allowed to change your experiment as 5 days have not passed yet.", Toast.LENGTH_LONG).show(); + Calendar c1 = Calendar.getInstance(); + c1.setTime(date1); + Calendar c2 = Calendar.getInstance(); + c2.setTime(date2); - } else if (differenceBetweenOldExperimentAndCurrent == 0 && getActivity().getSharedPreferences("expB", MODE_PRIVATE).getString("pickedB", "").equals("newPickedB")){ + int differenceBetweenOldExperimentAndCurrent = c1.get(Calendar.DAY_OF_YEAR) - c2.get(Calendar.DAY_OF_YEAR); - for (int i = 0; i < radioGroup.getChildCount(); i++) { - radioGroup.getChildAt(i).setEnabled(false); - } - Toast.makeText(getActivity().getApplicationContext(), "You are not allowed to change your experiment as you've just picked it.", Toast.LENGTH_LONG).show(); + if (differenceBetweenOldExperimentAndCurrent % 5 != 0){ + for (int i = 0; i < radioGroup.getChildCount(); i++) { + radioGroup.getChildAt(i).setEnabled(false); } - } else { - - if (differenceBetweenOldExperimentAndCurrent % 5 != 0){ - for (int i = 0; i < radioGroup.getChildCount(); i++) { - radioGroup.getChildAt(i).setEnabled(false); - } - Toast.makeText(getActivity().getApplicationContext(), "You are not allowed to change your experiment as 5 days have not passed yet.", Toast.LENGTH_LONG).show(); + Toast.makeText(getActivity().getApplicationContext(), "I'm sorry, you can't change your experiment as 5 days have not passed yet.", Toast.LENGTH_LONG).show(); } else if (differenceBetweenOldExperimentAndCurrent == 0 && getActivity().getSharedPreferences("exp", MODE_PRIVATE).getString("picked", "").equals("newPicked")){ @@ -183,81 +177,31 @@ public class Factors extends Fragment { for (int i = 0; i < radioGroup.getChildCount(); i++) { radioGroup.getChildAt(i).setEnabled(false); } - Toast.makeText(getActivity().getApplicationContext(), "You are not allowed to change your experiment as you've just picked it.", Toast.LENGTH_LONG).show(); - - } else if (differenceBetweenOldExperimentAndCurrent % 5 == 0 && differenceBetweenOldExperimentAndCurrent != 0){ - if (Integer.valueOf(currentHour) < 19) { - System.out.println("correct 5"); - for (int i = 0; i < radioGroup.getChildCount(); i++) { - radioGroup.getChildAt(i).setEnabled(false); - } - Toast.makeText(getActivity().getApplicationContext(), "You are not allowed to change your experiment yet. You can change it after 19:00 today.", Toast.LENGTH_LONG).show(); - - } else if (loggedIn % 5 != 1) { - System.out.println("correct 6"); - for (int i = 0; i < radioGroup.getChildCount(); i++) { - radioGroup.getChildAt(i).setEnabled(false); - } - Toast.makeText(getActivity().getApplicationContext(), "You are not allowed to change your experiment yet. You can change it after completing today's questionnaire.", Toast.LENGTH_LONG).show(); + Toast.makeText(getActivity().getApplicationContext(), "I'm sorry, you can't change your experiment yet as you've just picked it.", Toast.LENGTH_LONG).show(); - } - } - - /* - System.out.println("correct 1"); - if (!getActivity().getApplicationContext().getSharedPreferences("experiments", MODE_PRIVATE).getString("experiments", "").equals("No experiment for the initial day.")) { - System.out.println("correct 2"); - if (currentDate.equals(studyStartDate)) { - for (int i = 0; i < radioGroup.getChildCount(); i++) { - radioGroup.getChildAt(i).setEnabled(false); - } - - Toast.makeText(getActivity().getApplicationContext(), "You are not allowed to change your experiment yet as you've just picked it.", Toast.LENGTH_LONG).show(); - System.out.println("correct 3"); - } else if (differenceBetweenOldExperimentAndCurrent % 5 == 0) { - System.out.println("correct 4"); - if (Integer.valueOf(currentHour) < 19) { - System.out.println("correct 5"); - for (int i = 0; i < radioGroup.getChildCount(); i++) { - radioGroup.getChildAt(i).setEnabled(false); - } - Toast.makeText(getActivity().getApplicationContext(), "You are not allowed to change your experiment yet. You can change it after 19:00 today.", Toast.LENGTH_LONG).show(); - - } else if (loggedIn % 5 != 1) { - System.out.println("correct 6"); - for (int i = 0; i < radioGroup.getChildCount(); i++) { - radioGroup.getChildAt(i).setEnabled(false); - } - Toast.makeText(getActivity().getApplicationContext(), "You are not allowed to change your experiment yet. You can change it after completing today's questionnaire.", Toast.LENGTH_LONG).show(); - - } - } else { - System.out.println("correct 7"); - for (int i = 0; i < radioGroup.getChildCount(); i++) { - radioGroup.getChildAt(i).setEnabled(false); - } - Toast.makeText(getActivity().getApplicationContext(), "You are not allowed to change your experiment as 5 days have not passed yet.", Toast.LENGTH_LONG).show(); - - } - } else if (differenceBetweenOldExperimentAndCurrent == 0 && getActivity().getSharedPreferences("exp", MODE_PRIVATE).getString("picked", "").equals("newPicked")) { - System.out.println("correct 8"); - for (int i = 0; i < radioGroup.getChildCount(); i++) { - radioGroup.getChildAt(i).setEnabled(false); - } - Toast.makeText(getActivity().getApplicationContext(), "You are not allowed to change your experiment as you've just picked it.", Toast.LENGTH_LONG).show(); + } else if (differenceBetweenOldExperimentAndCurrent % 5 == 0 && differenceBetweenOldExperimentAndCurrent != 0) { + if (Integer.valueOf(currentHour) < 19) { + System.out.println("correct 5"); + for (int i = 0; i < radioGroup.getChildCount(); i++) { + radioGroup.getChildAt(i).setEnabled(false); + } + Toast.makeText(getActivity().getApplicationContext(), "I'm sorry, you can't change your experiment yet. You can change it after 19:00 today.", Toast.LENGTH_LONG).show(); - }*/ + } else if (loggedIn % 5 != 1) { + System.out.println("correct 6"); + for (int i = 0; i < radioGroup.getChildCount(); i++) { + radioGroup.getChildAt(i).setEnabled(false); } + Toast.makeText(getActivity().getApplicationContext(), "I'm sorry, you can't change your experiment yet. You can change it after completing today's questionnaire.", Toast.LENGTH_LONG).show(); + } +} - return factorsView; } - - private void SavePreferences(String key, int value){ getActivity().getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE).edit().putInt(key, value).apply(); } @@ -269,8 +213,13 @@ public class Factors extends Fragment { } + public static class FactorsDialog extends DialogFragment { + private String message; + private int hour, minute; + + @Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Use the Builder class for convenient dialog construction @@ -281,38 +230,69 @@ public class Factors extends Fragment { switch (experiment) { case 1: //increase bright light exposure builder.setMessage("Are you sure you want to choose this experiment? You will not be able to change it for the next 5 days. This experiment presumes:\nGetting sunlight exposure in the morrning;\nStaying at least half an hour in the sun per day;\nYour room needs to capture sunlight."); + message = "Stay out in the sun at least half an hour today!"; + hour = 12; + minute = 0; break; case 2: //wear glasses that block blue light during the night - builder.setMessage("Are you sure you want to choose this experiment? You will not be able to change it for the next 5 days. This experiment presumes:\nMaybe installing the f.lx app fromm google that warms up your computer display at night, to match your indoor lighting;\nIf needed - wearing glasses to block blue light during the night."); + builder.setMessage("Are you sure you want to choose this experiment? You will not be able to change it for the next 5 days. This experiment presumes:\nMaybe installing the f.lx app fromm google that warms up your computer display at night, to match your indoor lighting;\nIf needed - wearing glasses/a sleeping mask to block blue light during the night."); + message = "\"Use the \\\"f.lux\\\" app!\"!"; + hour = 12; + minute = 30; break; case 3: // turn off any bright lights 2 hours before going to bed builder.setMessage("Are you sure you want to choose this experiment? You will not be able to change it for the next 5 days. This experiment presumes:\nTurning off the TV/computer with 2 hours before going to bed;\nTurning off any other bright lights in your room with 2 hours before going to bed."); + message = "Going to bed soon?\", \"Do not forget to turn off your light with 2 hours before bed!"; + hour = 19; + minute = 30; break; case 5: // Do not drink caffeine within 6 hours builder.setMessage("Are you sure you want to choose this experiment? You will not be able to change it for the next 5 days. This experiment presumes:\nNot drinking coffee/soda/any energy drink with 6 hours before sleep."); + message = "Going to bed soon?\", \"Do not forget to turn off your light with 2 hours before bed!"; + hour = 19; + minute = 30; break; case 6: // Limit yourself to 4 cups of coffees per day; 10 canss of builder.setMessage("Are you sure you want to choose this experiment? You will not be able to change it for the next 5 days. This experiment presumes:\nLimiting yourself to drinking not more than 4 cups of coffee per day, 10 cans of soda or 2 energy drinks."); + message = "Limit yourself to 4 cups of coffee per day/10 cans of soda or 2 energy drinks!"; + hour = 14; + minute = 0; break; case 7: //Do not drink empty stomach builder.setMessage("Are you sure you want to choose this experiment? You will not be able to change it for the next 5 days. This experiment presumes:\nNever drinking caffeine (coffee, soda, energy drinks) on empty stomach."); + message = "Try not to drink caffeine on an empty stomach!"; + hour = 8; + minute = 0; break; case 9://Usually get up at the same time everyday, even on weekends builder.setMessage("Are you sure you want to choose this experiment? You will not be able to change it for the next 5 days. This experiment presumes:\nGoing to bed and waking up at the same time everyday."); + message = "Do not forget! Go to bed and wake up at the same time as yesterday!"; + hour = 18; + minute = 30; break; case 10: // Sleep no lesss than 7 hours per night builder.setMessage("Are you sure you want to choose this experiment? You will not be able to change it for the next 5 days. This experiment presumes:\nSleeping at least 7 hours per night."); + message = "Sleep no less than 7 hours per night"; + hour = 20; + minute = 0; break; case 11: //DO not go to bed unless you are tired. If you are not builder.setMessage("Are you sure you want to choose this experiment? You will not be able to change it for the next 5 days. This experiment presumes:\nNot going to bed unless you are tired;\nIf you are not, you should take a bath/read a book/stretch-short exercise/drink a hot cup of tea."); + message = "Do not go to bed unless you are tired. Read a book, take a bath, stretch or drink tea to relax!"; + hour = 20; + minute = 0; break; case 12: //Go to sleep at 22:30 PM the latest builder.setMessage("Are you sure you want to choose this experiment? You will not be able to change it for the next 5 days. This experiment presumes:\nNot going to sleep after 22:30."); + message = "Go to sleep at 10:30 PM the latest!!"; + hour = 21; + minute = 0; break; } + getActivity().getApplicationContext().getSharedPreferences("notification", MODE_PRIVATE).edit().putString("message", message).apply(); - builder.setPositiveButton("Submit", new DialogInterface.OnClickListener() { + builder.setPositiveButton("Submit", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //daca nu e blocat, atunci se updateaza experimentul, se blocheaza accesul si se incrementeaza nr de zile for (int i = 0; i < radioGroup.getChildCount(); i++) { @@ -329,23 +309,20 @@ public class Factors extends Fragment { getActivity().getSharedPreferences("date", MODE_PRIVATE).edit().putString("startExperiment", currentDate).apply(); getActivity().getSharedPreferences("exp", MODE_PRIVATE).getString("picked", "newPicked"); getActivity().getSharedPreferences("exp", MODE_PRIVATE).edit().putString("picked", "newPicked").apply(); - getActivity().getSharedPreferences("expB", MODE_PRIVATE).getString("pickedB", "newPickedB"); - getActivity().getSharedPreferences("expB", MODE_PRIVATE).edit().putString("pickedB", "newPickedB").apply(); // String participantID = getActivity().getApplicationContext().getSharedPreferences("name", MODE_PRIVATE).getString("participantID", "nothing"); - if (participantID.contains("B") || participantID.contains("b")){ - Intent intent = new Intent(getActivity().getApplicationContext(), B_MainMenu.class); + Intent intent = new Intent(getActivity().getApplicationContext(), AllPages.class); startActivity(intent); - } else { - Intent intent = new Intent(getActivity().getApplicationContext(), MainMenu.class); - startActivity(intent); - } + createQuestionnaireNotification(); + createExperimentNotification(); + + } }) @@ -358,5 +335,52 @@ public class Factors extends Fragment { // Create the AlertDialog object and return it return builder.create(); } + + private void createQuestionnaireNotification() { + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + CharSequence name = "reminder"; + int importance = NotificationManager.IMPORTANCE_DEFAULT; + NotificationChannel channel = new NotificationChannel("13", name, importance); + // Register the channel with the system; you can't change the importance + // or other notification behaviors after this + NotificationManager notificationManager = getActivity().getSystemService(NotificationManager.class); + notificationManager.createNotificationChannel(channel); + + + } + + Calendar calendar = Calendar.getInstance(); + calendar.set(Calendar.HOUR_OF_DAY, 19); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.SECOND, 0); + + if (Calendar.getInstance().after(calendar)) { + calendar.add(Calendar.DAY_OF_MONTH, 1); + } + Intent intent1 = new Intent(getActivity(), QuestionnaireBroadcast.class); + PendingIntent pendingIntent = PendingIntent.getBroadcast(getActivity(), 0, intent1, 0); + AlarmManager am1 = (AlarmManager) getActivity().getSystemService(getActivity().ALARM_SERVICE); + am1.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent); + } + + private void createExperimentNotification() { + + Calendar calendar = Calendar.getInstance(); + calendar.set(Calendar.HOUR_OF_DAY, hour); + calendar.set(Calendar.MINUTE, minute); + calendar.set(Calendar.SECOND, 0); + + if (Calendar.getInstance().after(calendar)) { + calendar.add(Calendar.DAY_OF_MONTH, 1); + } + + Intent intent1 = new Intent(getActivity(), ExperimentBroadcast.class); + PendingIntent pendingIntent = PendingIntent.getBroadcast(getActivity(), 0, intent1, 0); + AlarmManager am = (AlarmManager) getActivity().getSystemService(getActivity().ALARM_SERVICE); + am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent); + } } + + } diff --git a/app/src/main/java/com/uos/admin/sleepbetter/FirstPage.java b/app/src/main/java/com/uos/admin/sleepbetter/FirstPage.java index 22263c7..9664c95 100644 --- a/app/src/main/java/com/uos/admin/sleepbetter/FirstPage.java +++ b/app/src/main/java/com/uos/admin/sleepbetter/FirstPage.java @@ -10,10 +10,17 @@ import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; +import java.sql.Time; +import java.time.LocalDate; +import java.util.Calendar; +import java.util.Date; +import java.util.TimeZone; + public class FirstPage extends AppCompatActivity { private EditText nameBox = null; - private EditText participantID = null; + private TextView participantID = null; + private String participant = ""; @Override protected void onCreate(Bundle savedInstanceState) { @@ -22,21 +29,21 @@ public class FirstPage extends AppCompatActivity { nameBox = (EditText) findViewById(R.id.yourName); System.out.println("INPUT IS :" + nameBox.getText().toString()); - participantID = (EditText) findViewById(R.id.participantName); -/* - getApplicationContext().getSharedPreferences("MOOD", MODE_PRIVATE).edit().clear().commit(); - getApplicationContext().getSharedPreferences("name", MODE_PRIVATE).edit().clear().commit(); - getApplicationContext().getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE).edit().clear().commit(); - getApplicationContext().getSharedPreferences("questionnaire", MODE_PRIVATE).edit().clear().commit(); - getApplicationContext().getSharedPreferences("consent", MODE_PRIVATE).edit().clear().commit(); - getApplicationContext().getSharedPreferences("PREFERENCE", MODE_PRIVATE).edit().clear().commit(); - getApplicationContext().getSharedPreferences("bmhappy", MODE_PRIVATE).edit().clear().commit(); - getApplicationContext().getSharedPreferences("bmok", MODE_PRIVATE).edit().clear().commit(); - getApplicationContext().getSharedPreferences("bmnotok", MODE_PRIVATE).edit().clear().commit(); - getApplicationContext().getSharedPreferences("bmbad", MODE_PRIVATE).edit().clear().commit(); -*/ - getSharedPreferences("name", MODE_PRIVATE).getString("username", "nothing"); - getSharedPreferences("name", MODE_PRIVATE).getString("participantID", "nothing"); + participantID = (TextView) findViewById(R.id.participantID); + + Calendar calendar = Calendar.getInstance(TimeZone.getDefault()); + //getTime() returns the current date in default time zone + Date date = calendar.getTime(); + String day = String.valueOf(calendar.get(Calendar.DAY_OF_YEAR)); + String month = String.valueOf(calendar.get(Calendar.MONTH) + 1); + String year = String.valueOf(calendar.get(Calendar.YEAR)); + String hour = String.valueOf(calendar.get(Calendar.HOUR)); + String minute = String.valueOf(calendar.get(Calendar.MINUTE)); + String second = String.valueOf(calendar.get(Calendar.SECOND)); + String millisecond = String.valueOf(calendar.get(Calendar.MILLISECOND)); + + participant = day + month + year + hour + minute + second + millisecond; + participantID.setText("Participant ID: " + participant); final CheckBox consent = (CheckBox) findViewById(R.id.consentCheckbox); @@ -55,14 +62,10 @@ public class FirstPage extends AppCompatActivity { Intent intent = new Intent(getApplicationContext(), FirstPageConsent.class); String name = nameBox.getText().toString(); - String participant = participantID.getText().toString(); if (!name.equals("")){ getSharedPreferences("name", MODE_PRIVATE).edit().putString("username", name).apply(); } - if (!participant.equals("")){ - getSharedPreferences("name", MODE_PRIVATE).edit().putString("participantID", participant).apply(); - } startActivity(intent); @@ -72,14 +75,10 @@ public class FirstPage extends AppCompatActivity { String name = getSharedPreferences("name", MODE_PRIVATE).getString("username", "nothing"); - String participant = getSharedPreferences("name", MODE_PRIVATE).getString("participantID", "nothing"); if (!name.equals("nothing")){ nameBox.setText(name); } - if (!participant.equals("nothing")){ - participantID.setText(participant); - } Button button = (Button) findViewById(R.id.submitButton); button.setOnClickListener(new View.OnClickListener() { @@ -102,17 +101,10 @@ public class FirstPage extends AppCompatActivity { Boolean isFirstRun = getSharedPreferences("PREFERENCE", MODE_PRIVATE) .getBoolean("isFirstRun", true); - if (!isFirstRun && consent.isChecked() && !nameBox.getText().toString().equals("") && !participantID.getText().toString().equals("")) { + if (!isFirstRun && consent.isChecked() && !nameBox.getText().toString().equals("")) { //show start activity - - String participantID = getSharedPreferences("name", MODE_PRIVATE).getString("participantID", "nothing"); - - if (participantID.contains("B") || participantID.contains("b")){ - startActivity(new Intent(this, B_MainMenu.class)); - } else { - startActivity(new Intent(this, MainMenu.class)); - } + startActivity(new Intent(this, AllPages.class)); } @@ -131,28 +123,17 @@ public class FirstPage extends AppCompatActivity { if (nameBox.getText().toString().equals("")){ Toast.makeText(getApplicationContext(), "Please input your name", Toast.LENGTH_SHORT).show(); - } else if (participantID.getText().toString().equals("")){ - Toast.makeText(getApplicationContext(), "Please input your participant ID number", Toast.LENGTH_SHORT).show(); - } else { - if (participantID.getText().toString().contains("B") || participantID.getText().toString().contains("b") || participantID.getText().toString().contains("A") || participantID.getText().toString().contains("a")) { - Intent intent = new Intent(this, Demographics.class); + Intent intent = new Intent(this, Demographics.class); String name = nameBox.getText().toString(); - String participant = participantID.getText().toString(); getSharedPreferences("name", MODE_PRIVATE).edit().putString("username", name).apply(); getSharedPreferences("name", MODE_PRIVATE).edit().putString("participantID", participant).apply(); getSharedPreferences("PREFERENCE", MODE_PRIVATE).edit().putBoolean("isFirstRun", false).apply(); startActivity(intent); - } else { - Toast.makeText(getApplicationContext(), "Please input the CORRECT participant ID number (e.g. A1/B2 etc)", Toast.LENGTH_LONG).show(); - - } - - } diff --git a/app/src/main/java/com/uos/admin/sleepbetter/GoalDiary.java b/app/src/main/java/com/uos/admin/sleepbetter/GoalDiary.java index a420a8d..ab0caff 100644 --- a/app/src/main/java/com/uos/admin/sleepbetter/GoalDiary.java +++ b/app/src/main/java/com/uos/admin/sleepbetter/GoalDiary.java @@ -36,10 +36,8 @@ public class GoalDiary extends Fragment { @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { goalDiaryView = inflater.inflate(R.layout.act_diary, container, false); - ImageView imageView = (ImageView) goalDiaryView.findViewById(R.id.imageView29); - imageView.setImageResource(R.drawable.data); - Button button = (Button) goalDiaryView.findViewById(R.id.button); + Button button = (Button) goalDiaryView.findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { @@ -53,11 +51,28 @@ public class GoalDiary extends Fragment { }); + return goalDiaryView; + } + + private boolean isViewShown = false; + + @Override + public void setUserVisibleHint(boolean isVisibleToUser) { + super.setUserVisibleHint(isVisibleToUser); + if (getView() != null) { + isViewShown = true; + loadPageDataProcessing(); + } else { + isViewShown = false; + } + } + + public void loadPageDataProcessing() { + new Thread(new Runnable() { @Override public void run() { - userDatabase = Room.databaseBuilder(getActivity().getApplicationContext(), UserDatabase.class, DATABASE_NAME).fallbackToDestructiveMigration().build(); List<UserDiary> diaries = userDatabase.daoAccess().fetchDiary(); @@ -91,9 +106,7 @@ public class GoalDiary extends Fragment { } }).start(); - return goalDiaryView; } - public void updateDiary(String notee) { Date c = Calendar.getInstance().getTime(); @@ -142,8 +155,6 @@ public class GoalDiary extends Fragment { String diary_comments = getActivity().getApplicationContext().getSharedPreferences("diary", MODE_PRIVATE).getString("diary", ""); - - String[] diaries = diary_comments.split("gcm"); diaries[differenceOfDates] = diaries[differenceOfDates] + note + "."; diff --git a/app/src/main/java/com/uos/admin/sleepbetter/MainMenu.java b/app/src/main/java/com/uos/admin/sleepbetter/MainMenu.java deleted file mode 100644 index 44c527e..0000000 --- a/app/src/main/java/com/uos/admin/sleepbetter/MainMenu.java +++ /dev/null @@ -1,179 +0,0 @@ -package com.uos.admin.sleepbetter; - - -import android.app.AlarmManager; -import android.app.FragmentManager; -import android.app.FragmentTransaction; -import android.app.NotificationChannel; -import android.app.NotificationManager; -import android.app.PendingIntent; -import android.arch.persistence.room.Room; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.os.Build; -import android.os.Bundle; -import android.support.design.widget.TabLayout; -import android.support.v4.app.NotificationCompat; -import android.support.v4.view.ViewPager; -import android.view.View; -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.MenuItem; -import android.view.ViewGroup; -import android.widget.Button; -import android.widget.ImageView; -import android.widget.TextView; -import android.widget.Toast; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.Calendar; - -public class MainMenu extends AppCompatActivity { - static Class nextclass = MainMenu.class; - private static final String DATABASE_NAME = "user_db"; - - Toolbar toolbar; - TabLayout tabLayout; - ViewPager viewPager; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - setContentView(R.layout.act_main_menu); - - - toolbar = findViewById(R.id.toolbar_id); - setSupportActionBar(toolbar); - - - viewPager = (ViewPager) findViewById(R.id.viewPager_id); - - ViewPageAdapter adapter = new ViewPageAdapter(getSupportFragmentManager()); - - adapter.addSection(new Menu(), "Menu"); - adapter.addSection(new Factors(), "Experiments"); - adapter.addSection(new Data(), "Data"); - adapter.addSection(new GoalDiary(), "Goal Diary"); - adapter.addSection(new CalendarPage(), "Calendar"); - adapter.addSection(new Update(), "Questionnaire"); - - viewPager.setAdapter(adapter); - - tabLayout = (TabLayout) findViewById(R.id.tabLayout_id); - - tabLayout.setupWithViewPager(viewPager); - - tabLayout.getTabAt(0).setIcon(R.drawable.imageedit_32_4626940004); - tabLayout.getTabAt(1).setIcon(R.drawable.experiments); - tabLayout.getTabAt(2).setIcon(R.drawable.data); - tabLayout.getTabAt(3).setIcon(R.drawable.diaryic); - tabLayout.getTabAt(4).setIcon(R.drawable.calendar); - tabLayout.getTabAt(5).setIcon(R.drawable.pen); - } - - -/* - @Override - public void onBackPressed() { - DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); - if (drawer.isDrawerOpen(GravityCompat.START)) { - drawer.closeDrawer(GravityCompat.START); - } else { - - int count = getFragmentManager().getBackStackEntryCount(); - - if (count == 0) { - System.out.println("returns"); - moveTaskToBack(true); - } else { - getFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); - } - } - } - - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. - int id = item.getItemId(); - - //noinspection SimplifiableIfStatement - - return super.onOptionsItemSelected(item); - }*/ -/* - @SuppressWarnings("StatementWithEmptyBody") - @Override - public boolean onNavigationItemSelected(MenuItem item) { - // Handle navigation view item clicks here. - int id = item.getItemId(); - FragmentManager fragmentManager = getFragmentManager(); - FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); - - if (id == R.id.nav_factors) { - fragmentTransaction.replace(R.id.content_frame, new Factors()); - } else if (id == R.id.nav_goal_diary) { - fragmentTransaction.replace(R.id.content_frame, new GoalDiary()); - } else if (id == R.id.nav_data) { - fragmentTransaction.replace(R.id.content_frame, new Data()); - } else if (id == R.id.nav_questionnaire) { - - String experiment = getSharedPreferences("name", MODE_PRIVATE).getString("experiment", "nothing"); - - if (checkIfAllowsQuestionnaire()) { - - if (experiment.equals(getString(R.string.firstLight))) { - fragmentTransaction.replace(R.id.content_frame, new Update_Light_Bright()); - } else if (experiment.equals(getString(R.string.secondLight))) { - fragmentTransaction.replace(R.id.content_frame, new Update_Light_Glasses()); - } else if (experiment.equals(getString(R.string.thirdLight))) { - fragmentTransaction.replace(R.id.content_frame, new Update_Light_TurnOffBright()); - } else if (experiment.equals(getString(R.string.firstCaffeine))) { - fragmentTransaction.replace(R.id.content_frame, new Update_Caffeine_6hours()); - } else if (experiment.equals(getString(R.string.secondCaffeine))) { - fragmentTransaction.replace(R.id.content_frame, new Update_Caffeine_limit()); - } else if (experiment.equals(getString(R.string.thirdCaffeine))) { - fragmentTransaction.replace(R.id.content_frame, new Update_Caffeine_Empty()); - } else if (experiment.equals(getString(R.string.firstSchedule))) { - fragmentTransaction.replace(R.id.content_frame, new Update_Schedule_SameTime()); - } else if (experiment.equals(getString(R.string.secondSchedule))) { - fragmentTransaction.replace(R.id.content_frame, new Update_Schedule_7hours()); - } else if (experiment.equals(getString(R.string.thirdSchedule))) { - fragmentTransaction.replace(R.id.content_frame, new Update_Schedule_Relax()); - } else if (experiment.equals(getString(R.string.fourthSchedule))) { - fragmentTransaction.replace(R.id.content_frame, new Update_Schedule_Midnight()); - } else { - fragmentTransaction.replace(R.id.content_frame, new Update()); - } - - } - } else if (id == R.id.nav_calendar) { - - fragmentTransaction.replace(R.id.content_frame, new CalendarPage()); - - } - - fragmentTransaction.addToBackStack(null); - fragmentTransaction.commit(); - getFragmentManager().executePendingTransactions(); - - DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); - drawer.closeDrawer(GravityCompat.START); - return true; - } -*/ - - -} \ No newline at end of file diff --git a/app/src/main/java/com/uos/admin/sleepbetter/Menu.java b/app/src/main/java/com/uos/admin/sleepbetter/Menu.java index 9c360f3..08a5f0e 100644 --- a/app/src/main/java/com/uos/admin/sleepbetter/Menu.java +++ b/app/src/main/java/com/uos/admin/sleepbetter/Menu.java @@ -1,24 +1,15 @@ package com.uos.admin.sleepbetter; -import android.app.AlarmManager; -import android.app.NotificationChannel; -import android.app.NotificationManager; -import android.app.PendingIntent; import android.arch.persistence.room.Room; -import android.content.BroadcastReceiver; -import android.content.Context; import android.content.Intent; -import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; -import android.support.v4.app.NotificationCompat; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; -import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; @@ -34,6 +25,7 @@ import static android.content.Context.MODE_PRIVATE; public class Menu extends Fragment { View mainPage; + private static final String DATABASE_NAME = "user_db"; public Menu(){ @@ -46,15 +38,67 @@ public class Menu extends Fragment { mainPage = inflater.inflate(R.layout.act_menu, container, false); + Button myExperimentButton = mainPage.findViewById(R.id.submitButton); + myExperimentButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + startActivity(new Intent(getActivity(), MyCurrentExperiment.class)); + } + + }); + + Button button1 = mainPage.findViewById(R.id.whatSleep); + button1.setOnClickListener(new View.OnClickListener() { + + public void onClick(View v) { + startActivity(new Intent(getActivity(), WhatIsSleep.class)); + } + + }); + + Button button3 = mainPage.findViewById(R.id.WhatExperiments); + button3.setOnClickListener(new View.OnClickListener() { + + public void onClick(View v) { + startActivity(new Intent(getActivity(), WhatExperiments.class)); + } + + }); + + + TextView navUsername = (TextView) mainPage.findViewById(R.id.editText3); + String name = getActivity().getApplicationContext().getSharedPreferences("name", MODE_PRIVATE).getString("username", "nothing"); + navUsername.setText(name); + + + TextView participantID = (TextView) mainPage.findViewById(R.id.partID); + String id = getActivity().getApplicationContext().getSharedPreferences("name", MODE_PRIVATE).getString("participantID", "nothing"); + participantID.setText("Participant ID: " + id); + + return mainPage; + + } + + private boolean isViewShown = false; + + @Override + public void setUserVisibleHint(boolean isVisibleToUser) { + super.setUserVisibleHint(isVisibleToUser); + if (getView() != null) { + isViewShown = true; + loadPageDataProcessing(); + } else { + isViewShown = false; + } + } -/* + public void loadPageDataProcessing(){ Date c = Calendar.getInstance().getTime(); SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy"); final String currentDate = df.format(c); - String startingDate = getSharedPreferences("date", MODE_PRIVATE).getString("startingDate", ""); + String startingDate = getActivity().getApplicationContext().getSharedPreferences("date", MODE_PRIVATE).getString("startingDate", ""); Date date1 = null; Date date2 = null; @@ -79,17 +123,17 @@ public class Menu extends Fragment { final int finalShouldBe = shouldBe; - String expStartDate = getSharedPreferences("date", MODE_PRIVATE).getString("startExperiment", ""); + String expStartDate = getActivity().getApplicationContext().getSharedPreferences("date", MODE_PRIVATE).getString("startExperiment", ""); if (shouldBe == 0 && expStartDate.equals("")) { - Toast.makeText(getApplicationContext(), "Please choose an experiment.", Toast.LENGTH_LONG).show(); + Toast.makeText(getActivity().getApplicationContext(), "Please choose an experiment.", Toast.LENGTH_LONG).show(); } new Thread(new Runnable() { @Override public void run() { - UserDatabase uDatabase = Room.databaseBuilder(getApplicationContext(), UserDatabase.class, DATABASE_NAME).fallbackToDestructiveMigration().build(); + UserDatabase uDatabase = Room.databaseBuilder(getActivity().getApplicationContext(), UserDatabase.class, DATABASE_NAME).fallbackToDestructiveMigration().build(); int loggedIn = uDatabase.daoAccess().fetchUserQuestionnaires().size(); @@ -98,17 +142,16 @@ public class Menu extends Fragment { if (misses >=1){ - String moods_string = getApplicationContext().getSharedPreferences("moods", MODE_PRIVATE).getString("moods", ""); + String moods_string = getActivity().getApplicationContext().getSharedPreferences("moods", MODE_PRIVATE).getString("moods", ""); String[] moods = moods_string.split("gcm"); ArrayList<String> moodsArrayList = new ArrayList<String>(Arrays.asList(moods)); for (int i=0; i<misses; i++){ - // adaugam -1 in tabel UserQuestionnaire user = new UserQuestionnaire(); - String username = getApplicationContext().getSharedPreferences("name", MODE_PRIVATE).getString("participantID", "nothing"); user.setUsername(username); + String username = getActivity().getApplicationContext().getSharedPreferences("name", MODE_PRIVATE).getString("participantID", "nothing"); user.setUsername(username); user.setDate(currentDate); user.setUsername(username); user.setHowLong(-1); @@ -122,14 +165,14 @@ public class Menu extends Fragment { user.setProblem(-1); user.setMood(-1); - getSharedPreferences("questionnaire", MODE_PRIVATE).edit().putInt("howLong", -1).apply(); - getSharedPreferences("questionnaire", MODE_PRIVATE).edit().putInt("awake", -1).apply(); - getSharedPreferences("questionnaire", MODE_PRIVATE).edit().putInt("earlier", -1).apply(); - getSharedPreferences("questionnaire", MODE_PRIVATE).edit().putInt("quality", -1).apply(); - getSharedPreferences("questionnaire", MODE_PRIVATE).edit().putInt("impactMood", -1).apply(); - getSharedPreferences("questionnaire", MODE_PRIVATE).edit().putInt("impactActivities", -1).apply(); - getSharedPreferences("questionnaire", MODE_PRIVATE).edit().putInt("impactGeneral", -1).apply(); - getSharedPreferences("MOOD", MODE_PRIVATE).edit().putFloat("mood", (float) -1).apply(); + getActivity().getApplicationContext().getSharedPreferences("questionnaire", MODE_PRIVATE).edit().putInt("howLong", -1).apply(); + getActivity().getApplicationContext().getSharedPreferences("questionnaire", MODE_PRIVATE).edit().putInt("awake", -1).apply(); + getActivity().getApplicationContext().getSharedPreferences("questionnaire", MODE_PRIVATE).edit().putInt("earlier", -1).apply(); + getActivity().getApplicationContext().getSharedPreferences("questionnaire", MODE_PRIVATE).edit().putInt("quality", -1).apply(); + getActivity().getApplicationContext().getSharedPreferences("questionnaire", MODE_PRIVATE).edit().putInt("impactMood", -1).apply(); + getActivity().getApplicationContext().getSharedPreferences("questionnaire", MODE_PRIVATE).edit().putInt("impactActivities", -1).apply(); + getActivity().getApplicationContext().getSharedPreferences("questionnaire", MODE_PRIVATE).edit().putInt("impactGeneral", -1).apply(); + getActivity().getApplicationContext().getSharedPreferences("MOOD", MODE_PRIVATE).edit().putFloat("mood", (float) -1).apply(); //setting mood value to -1 in shared preferences @@ -137,8 +180,8 @@ public class Menu extends Fragment { moodsArrayList.add("-1"); - Report rep = new Report(uDatabase, getApplicationContext()); - rep.save(username, false, getSharedPreferences("consent", MODE_PRIVATE).getString("consent", "nothing")); + Report rep = new Report(uDatabase, getActivity().getApplicationContext()); + rep.save(username, false, getActivity().getApplicationContext().getSharedPreferences("consent", MODE_PRIVATE).getString("consent", "nothing")); } moods = moodsArrayList.toArray(moods); @@ -147,16 +190,10 @@ public class Menu extends Fragment { for (int i = 0; i < moods.length; i++) { sb.append(moods[i]).append("gcm"); } - getApplicationContext().getSharedPreferences("moods", MODE_PRIVATE).edit().putString("moods", sb.toString()).apply(); + getActivity().getApplicationContext().getSharedPreferences("moods", MODE_PRIVATE).edit().putString("moods", sb.toString()).apply(); } - - - - - - } //scoatem variabila days si verificam: daca se imparte la 5, si nu e locked, @@ -165,13 +202,12 @@ public class Menu extends Fragment { //update experiments - String experiments = getSharedPreferences("experiments", MODE_PRIVATE).getString("experiments", ""); + String experiments = getActivity().getApplicationContext().getSharedPreferences("experiments", MODE_PRIVATE).getString("experiments", ""); String[] experimentsArray = experiments.split("gcm"); - //+1 to include dy 0 if (shouldBe> experimentsArray.length){ - String currentExperiment = getSharedPreferences("name", MODE_PRIVATE).getString("experiment", "nothing"); + String currentExperiment = getActivity().getApplicationContext().getSharedPreferences("name", MODE_PRIVATE).getString("experiment", "nothing"); ArrayList<String> experimentsArrayList = new ArrayList<String>(Arrays.asList(experimentsArray)); for (int i=0; i< (shouldBe - experimentsArray.length); i++){ @@ -184,75 +220,11 @@ public class Menu extends Fragment { for (int i = 0; i < experimentsArray.length; i++) { sb.append(experimentsArray[i]).append("gcm"); } - getSharedPreferences("experiments", MODE_PRIVATE).edit().putString("experiments", sb.toString()).apply(); - + getActivity().getApplicationContext().getSharedPreferences("experiments", MODE_PRIVATE).edit().putString("experiments", sb.toString()).apply(); } - //context.getSharedPreferences("questionnaire", MODE_PRIVATE).edit().putBoolean("completed", false).apply(); - //context.getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE).edit().putBoolean("locked", true).apply(); - - //scoatem variabila days si verificam: daca se imparte la 5, si nu e locked, - ImageView imageView = findViewById(R.id.imageView2); - - */ - - /* imageView.setImageResource(R.drawable.sleep); - - - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); - setSupportActionBar(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); - - View headerView = navigationView.getHeaderView(0); - TextView navUsername = (TextView) headerView.findViewById(R.id.nameOfUser); - - String name = getSharedPreferences("name", MODE_PRIVATE).getString("username", "nothing"); - navUsername.setText(name); -*/ - //NOTIFICATION DEMO - - /* - this.createNotificationChannel(); - this.setNotifications(); - this.setFirstSpecialNotification(); -///END NOTIFICATIONs - - Button button1 = (Button) findViewById(R.id.whatSleep); - - button1.setOnClickListener(new View.OnClickListener() { - - public void onClick(View v) { - - goToWhatIsSleep(); - - } - - }); - - Button button3 = (Button) findViewById(R.id.WhatExperiments); - - button3.setOnClickListener(new View.OnClickListener() { - - public void onClick(View v) { - - goToWhatExperiments(); - - } - - }); - - - TextView remainedDaysText = (TextView) findViewById(R.id.youHave); + TextView remainedDaysText = (TextView) mainPage.findViewById(R.id.youHave); if (expStartDate.equals("")){ remainedDaysText.setText("Please choose your experiment in the Experiments section."); @@ -271,7 +243,7 @@ public class Menu extends Fragment { int experimentDaysDifference = c1.get(Calendar.DAY_OF_YEAR) - c3.get(Calendar.DAY_OF_YEAR); - int difference = 5 - experimentDaysDifference; + int difference = 5 - (experimentDaysDifference % 5); remainedDaysText.setText("You have " + difference + " days left of the current experiment."); @@ -286,234 +258,6 @@ public class Menu extends Fragment { } } -*/ - return mainPage; - - } -/* - private void goToWhatIsSleep() { - Intent intent = new Intent(this, WhatIsSleep.class); - - startActivity(intent); - - } - - private void goToWhatExperiments() { - Intent intent = new Intent(this, WhatExperiments.class); - - startActivity(intent); - - } - - private boolean checkIfAllowsQuestionnaire(){ - - Calendar calendar1 = Calendar.getInstance(); - SimpleDateFormat formatter1 = new SimpleDateFormat("HH:mm"); - String currentHour = formatter1.format(calendar1.getTime()); - - SimpleDateFormat formatter2 = new SimpleDateFormat("dd-MMM-yyyy"); - String currentDate = formatter2.format(calendar1.getTime()); - - - String startingDate = getSharedPreferences("date", MODE_PRIVATE).getString("startingDate", ""); - - Date date1 = null; - Date date2 = null; - - SimpleDateFormat dates = new SimpleDateFormat("dd-MMM-yyyy"); - - //Setting dates - try { - date1 = dates.parse(currentDate); - date2 = dates.parse(startingDate); - } catch (ParseException e) { - e.printStackTrace(); - } - - Calendar c1 = Calendar.getInstance(); - c1.setTime(date1); - - Calendar c2 = Calendar.getInstance(); - c2.setTime(date2); - - int shouldBe = c1.get(Calendar.DAY_OF_YEAR) - c2.get(Calendar.DAY_OF_YEAR); - - - String experiments = getSharedPreferences("experiments", MODE_PRIVATE).getString("experiments", ""); - - String[] experimentsArray = experiments.split("gcm"); - - System.out.println(experimentsArray.length); - if (getApplicationContext().getSharedPreferences("experiments", MODE_PRIVATE).getString("experiments", "").equals("No experiment for the initial day.") && shouldBe == 0) { - Toast.makeText(getApplicationContext(), "You are not allowed to fill in today's questionnaire. Choose an experiment if you haven't.", Toast.LENGTH_LONG).show(); - return false; - } else if (currentHour.compareTo("18:59") < 0) { - Toast.makeText(getApplicationContext(), "You are not allowed to fill in today's questionnaire yet. Come back at 19:00.", Toast.LENGTH_LONG).show(); - - return false; - } else if (experimentsArray.length - shouldBe >= 1) { - Toast.makeText(getApplicationContext(), "You are not allowed to fill in today's questionnaire. Come back tomorrow.", Toast.LENGTH_LONG).show(); - return false; - } else { - return true; - } } - private void createNotificationChannel() { - // Create the NotificationChannel, but only on API 26+ because - // the NotificationChannel class is new and not in the support library - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - CharSequence name = "reminder"; - int importance = NotificationManager.IMPORTANCE_DEFAULT; - NotificationChannel channel = new NotificationChannel("13", name, importance); - // Register the channel with the system; you can't change the importance - // or other notification behaviors after this - NotificationManager notificationManager = getSystemService(NotificationManager.class); - notificationManager.createNotificationChannel(channel); - } - } - - private void setAlarmManager(int hour, int minute, final String title, final String message) { - - getSharedPreferences("notification", MODE_PRIVATE).getString("title", "nothing"); - getSharedPreferences("notification", MODE_PRIVATE).edit().putString("title", title).apply(); - getSharedPreferences("notification", MODE_PRIVATE).getString("message", "nothing"); - getSharedPreferences("notification", MODE_PRIVATE).edit().putString("message", message).apply(); - - Calendar calendar = Calendar.getInstance(); - calendar.set(Calendar.HOUR_OF_DAY, hour); - calendar.set(Calendar.MINUTE, minute); - calendar.set(Calendar.SECOND, 0); - - if (Calendar.getInstance().after(calendar)) { - calendar.add(Calendar.DAY_OF_MONTH, 1); - } - - Intent intent1 = new Intent(MainMenu.this, Broadcast1.class); - PendingIntent pendingIntent = PendingIntent.getBroadcast(MainMenu.this, 0, intent1, 0); - AlarmManager am = (AlarmManager) MainMenu.this.getSystemService(MainMenu.this.ALARM_SERVICE); - am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent); - } - - private void setFirstSpecialNotification() { - Calendar calendar = Calendar.getInstance(); - calendar.set(Calendar.HOUR_OF_DAY, 19); - calendar.set(Calendar.MINUTE, 0); - calendar.set(Calendar.SECOND, 0); - - if (Calendar.getInstance().after(calendar)) { - calendar.add(Calendar.DAY_OF_MONTH, 1); - } - Intent intent1 = new Intent(MainMenu.this, Broadcast2.class); - PendingIntent pendingIntent = PendingIntent.getBroadcast(MainMenu.this, 0, intent1, 0); - AlarmManager am1 = (AlarmManager) MainMenu.this.getSystemService(MainMenu.this.ALARM_SERVICE); - am1.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent); - - } - - //produce the required notifications - private void setNotifications() { - int experiment = getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE).getInt("KEY_SAVED_RADIO_BUTTON_INDEX", 0); - - switch (experiment) { - case 1: //increase bright light exposure - setAlarmManager(12, 0, "Remember:", "Stay out in the sun at least half an hour today!"); - break; - case 2: //wear glasses that block blue light during the night - setAlarmManager(12, 30, "Remember:", "Use the \"f.lux\" app!"); - break; - case 3: // turn off any bright lights 2 hours before going to bed - setAlarmManager(19, 30, "Going to bed soon?", "Do not forget to turn off your light with 2 hours before bed!"); - break; - case 5: // Do not drink caffeine within 6 hours - setAlarmManager(15, 0, "Remember:", "Do not drink caffeine with 6 hours before going to sleep!"); - break; - case 6: // Limit yourself to 4 cups of coffees per day; 10 canss of - setAlarmManager(16, 24, "Remember:", "Limit yourself to 4 cups of coffee per day/10 cans of soda or 2 energy drinks!"); - break; - case 7: //Do not drink empty stomach - setAlarmManager(8, 0, "Remember:", "Try not to drink caffeine on an empty stomach!"); - break; - case 9://Usually get up at the same time everyday, even on weekends - setAlarmManager(18, 30, "Remember:", "Do not forget! Go to bed and wake up at the same time as yesterday!"); - break; - case 10: // Sleep no lesss than 7 hours per night - setAlarmManager(19, 50, "Remember:", "Sleep no less than 7 hours per night!"); - break; - case 11: //DO not go to bed unless you are tired. If you are not - setAlarmManager(20, 00, "Remember", "Do not go to bed unless you are tired. Read a book, take a bath, stretch or drink tea to relax!"); - break; - case 12: //Go to sleep at 22:30 PM the latest - setAlarmManager(21, 00, "Remember:", "Go to sleep at 10:30 PM the latest!"); - break; - } - - } - - public static class Broadcast1 extends BroadcastReceiver { - @Override - public void onReceive(Context context, Intent intent) { - - String titleM = context.getSharedPreferences("notification", MODE_PRIVATE).getString("title", "nothing"); - String messageM = context.getSharedPreferences("notification", MODE_PRIVATE).getString("message", "nothing"); - - - long when = System.currentTimeMillis(); - NotificationManager notificationManager = (NotificationManager) context - .getSystemService(Context.NOTIFICATION_SERVICE); - - Intent notificationIntent = new Intent(context, nextclass); - notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - - PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, - notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); - - - // Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); - - NotificationCompat.Builder mNotifyBuilder = new NotificationCompat.Builder(context, "13") - .setSmallIcon(R.drawable.pill) - .setContentTitle(titleM) - .setStyle(new NotificationCompat.BigTextStyle() - .bigText(messageM)) - .setContentText(messageM) - .setAutoCancel(true).setWhen(when) - .setContentIntent(pendingIntent); - notificationManager.notify(13, mNotifyBuilder.build()); -// - } - } - - public static class Broadcast2 extends BroadcastReceiver { - - //intrebarea este daca, aunci cand va veni momentul a schimbe si experimentul - daca o sa ii dea si alarma veche cu complete questionnaire si cea noua cu both complete the questionnaire and the experiment - @Override - public void onReceive(Context context, Intent intent) { - - long when = System.currentTimeMillis(); - NotificationManager notificationManager = (NotificationManager) context - .getSystemService(Context.NOTIFICATION_SERVICE); -//AICIII - Intent notificationIntent = new Intent(context, MainMenu.class); - - notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - - PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, - notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); - - - // Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); - - NotificationCompat.Builder mNotifyBuilder = new NotificationCompat.Builder(context, "13") - .setSmallIcon(R.drawable.pill) - .setContentTitle("Questionnaire") - .setContentText("Remember to complete your questionnaire") - .setAutoCancel(true).setWhen(when) - .setContentIntent(pendingIntent); - notificationManager.notify(20, mNotifyBuilder.build()); - - - } - } -*/ } diff --git a/app/src/main/java/com/uos/admin/sleepbetter/MyCurrentExperiment.java b/app/src/main/java/com/uos/admin/sleepbetter/MyCurrentExperiment.java new file mode 100644 index 0000000..27bc544 --- /dev/null +++ b/app/src/main/java/com/uos/admin/sleepbetter/MyCurrentExperiment.java @@ -0,0 +1,72 @@ +package com.uos.admin.sleepbetter; + +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; + +public class MyCurrentExperiment extends AppCompatActivity { + + protected void onCreate(Bundle savedInstanceState) { + + + super.onCreate(savedInstanceState); + setContentView(R.layout.act_current_xperiment); + + + Button button = (Button) findViewById(R.id.submitButton); + button.setOnClickListener(new View.OnClickListener() { + + public void onClick(View v) { + + Intent intent = new Intent(getApplicationContext(), AllPages.class); + + startActivity(intent); + } + + }); + + TextView experimentTitle = (TextView) findViewById(R.id.experimentTitleID); + experimentTitle.setText("Experiment: " + getApplicationContext().getSharedPreferences("name", Context.MODE_PRIVATE).getString("experiment", " ")); + + TextView description = (TextView) findViewById(R.id.descriptionID); + + int experiment = getApplicationContext().getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE).getInt("KEY_SAVED_RADIO_BUTTON_INDEX", 0); + + switch (experiment) { + case 1: //increase bright light exposure + description.setText("Exposure to sunlight should occur in the morning upon awakening, typically within the first hour after crawling out of bed. It is best to spend 30 to 45 minutes getting direct sunlight exposure into the eyes;\\nSpend at least half an hour in the sun during the day as well, by exercising, walking or just any other sort of activity;\\nIt is recommended that your bedroom can capture the sunlight during the day - leaving your curtains open;\\nMoreover, don't worry if it's a cloudy day, because even when filtered through clouds or rain, the sunlight will continue to have its effect."); + break; + case 2: //wear glasses that block blue light during the night + description.setText("Blue light - coming from LED screens or even from the sun - in the evening tricks your brain into thinking it’s daytime, which inhibits the production of melatonin and reduces both the quantity and quality of your sleep;\\nWearing sleep masks or glasses during the night is recommended here;\\nAlso, installing the f.lx app ( https://justgetflux.com/ ) would be highly recommended as it warms up your computer display at night, to match your indoor lighting;\\nManually adjusting the brightness on your devices wuld also help with this matter."); + break; + case 3: // turn off any bright lights 2 hours before going to bed + description.setText("Light makes you feel alert, which isn't what you want when you need to sleep;\\nTherefore, try turning off the TV, the computer, or any other LED-light device you are using with 2 hours before going to bed."); + break; + case 5: // Do not drink caffeine within 6 hours + description.setText("It is highly recommended not drinking any product containing caffeine with 6 hours before going to sleep;\\nThat is either coffee, soft drinks such as Coke, Fanta etc, some tea brews - such as green tea or black tea, and of course, energy drinks."); + break; + case 6: // Limit yourself to 4 cups of coffees per day; 10 canss of + description.setText("During the day, please limit yourself to drinking not more than 4 cups of coffee (about 945 ml), 10 cans of soda (about 3.3 l) such as Fanta or Coke, or 2 energy drinks - of any kind."); + break; + case 7: //Do not drink empty stomach + description.setText("After you wake up, we highly recommend not drinking any products containing caffeine on empty stomach (before eating any food);\\nThat is either coffee, soft drinks such as Coke, Fanta etc, some tea brews - such as green tea or black tea, and of course, energy drinks."); + break; + case 9://Usually get up at the same time everyday, even on weekends + description.setText("Going to bed and waking up at the same time everyday, even during the weekend, or during holidays;\\nIt's important to have a sleeping schedule as your body loves ROUTINE."); + break; + case 10: // Sleep no lesss than 7 hours per night + description.setText("It can happen very often that you don't feel sleepy close to bedtime. That can be caused by a lot of other factors, like the caffeine in your body, light exposure, adrenaline etc;\\n Either way, before going to sleep, we recommend trying one of the next few activities:\\nTake a warm bath to let your body relax;\\nRead a book to relax your mind;\\nTry doing a few exercises or stretching;\\nDrink a hot cup of tea, but be careful so that it doesn not containt caffeine (such as black tea and green tea);\\nAny other activity that works well for yourself and helps your mind and body relax."); + break; + case 11: //DO not go to bed unless you are tired. If you are not + description.setText("Going to sleep no later than 22:30 in order to regulate you sleep cycles to an appropriate bedtime hour."); + break; + case 12: //Go to sleep at 22:30 PM the latest + description.setText("Since you haven't chosen an experiment from the \\\"Experiment\\\" section yet, this section is unavailable."); + break; + } + } +} diff --git a/app/src/main/java/com/uos/admin/sleepbetter/QFinal.java b/app/src/main/java/com/uos/admin/sleepbetter/QFinal.java index f5af8b4..d7cbf2f 100644 --- a/app/src/main/java/com/uos/admin/sleepbetter/QFinal.java +++ b/app/src/main/java/com/uos/admin/sleepbetter/QFinal.java @@ -1,19 +1,25 @@ package com.uos.admin.sleepbetter; -import android.app.Fragment; + +import android.app.AlertDialog; +import android.app.Dialog; import android.arch.persistence.room.Room; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.Bundle; import android.support.annotation.Nullable; +import android.support.v4.app.DialogFragment; +import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.RadioGroup; import android.widget.Toast; +import android.support.v4.app.FragmentManager; import java.text.DecimalFormat; import java.text.SimpleDateFormat; @@ -29,6 +35,8 @@ public class QFinal extends Fragment { private static final String DATABASE_NAME = "user_db"; private UserDatabase userDatabase; + private static boolean goToMenu = false; + View questionnaireView; @Nullable @Override @@ -52,15 +60,36 @@ public class QFinal extends Fragment { } private void loopForSending(){ - // System.out.println("IS NETWORK : " + isConnected()); if (isConnected()){ goToMenu(); } else { - QInitial.InternetDialog dial = new QInitial.InternetDialog(); - dial.show(getFragmentManager(), "dialog"); + InternetDialog dial = new InternetDialog(); + FragmentManager fragmentManager = getFragmentManager(); + dial.show(fragmentManager, "dialog"); } } + public static class InternetDialog extends DialogFragment { + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + + builder.setMessage("Make sure you have internet connection. When ready, press - OK."); + builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.dismiss(); + } + }); + builder.setNegativeButton("I can't access the internet", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.dismiss(); + goToMenu = true; + } + }); + return builder.create(); + } + } public void goToMenu(){ @@ -124,10 +153,7 @@ public class QFinal extends Fragment { DecimalFormat formatting = new DecimalFormat("#.##"); mood = Double.parseDouble(formatting.format(mood)); - - String participantID = getActivity().getApplicationContext().getSharedPreferences("name", MODE_PRIVATE).getString("participantID", "nothing"); - - startActivity(new Intent(getActivity().getApplicationContext(), MainMenu.class)); + startActivity(new Intent(getActivity().getApplicationContext(), AllPages.class)); Date c = Calendar.getInstance().getTime(); diff --git a/app/src/main/java/com/uos/admin/sleepbetter/QInitial.java b/app/src/main/java/com/uos/admin/sleepbetter/QInitial.java index 90bd21c..8800d4f 100644 --- a/app/src/main/java/com/uos/admin/sleepbetter/QInitial.java +++ b/app/src/main/java/com/uos/admin/sleepbetter/QInitial.java @@ -2,7 +2,6 @@ package com.uos.admin.sleepbetter; import android.app.AlertDialog; import android.app.Dialog; -import android.app.DialogFragment; import android.arch.persistence.room.Room; import android.content.Context; import android.content.DialogInterface; @@ -10,6 +9,8 @@ import android.content.Intent; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.Bundle; +import android.support.v4.app.DialogFragment; +import android.support.v4.app.Fragment; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; @@ -27,11 +28,11 @@ public class QInitial extends AppCompatActivity { private static final String DATABASE_NAME = "user_db"; private UserDatabase userDatabase; + private static boolean goToMenu = false; @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); setContentView(R.layout.act_ques_initial); @@ -41,11 +42,7 @@ public class QInitial extends AppCompatActivity { button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { - loopForSending(); - - - } }); @@ -53,12 +50,11 @@ public class QInitial extends AppCompatActivity { } private void loopForSending(){ - // System.out.println("IS NETWORK : " + isConnected()); - if (isConnected()){ + if (isConnected() || goToMenu){ goToMenu(); } else { InternetDialog dial = new InternetDialog(); - dial.show(getFragmentManager(), "dialog"); + dial.show(getSupportFragmentManager(), "dialog"); } } @@ -75,19 +71,20 @@ public class QInitial extends AppCompatActivity { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { - // Use the Builder class for convenient dialog construction AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - builder.setMessage("You need to have internet connection to proceed."); - builder.setPositiveButton("Close", new DialogInterface.OnClickListener() { + builder.setMessage("Make sure you have internet connection. When ready, press - OK."); + builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { - // FIRE ZE MISSILES! dialog.dismiss(); - - } }); - // Create the AlertDialog object and return it + builder.setNegativeButton("I can't access the internet", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.dismiss(); + goToMenu = true; + } + }); return builder.create(); } } @@ -170,27 +167,13 @@ public class QInitial extends AppCompatActivity { DecimalFormat formatting = new DecimalFormat("#.##"); mood = Double.parseDouble(formatting.format(mood)); - Intent intent = new Intent(this, MainMenu.class); - Intent intentB = new Intent(this, B_MainMenu.class); - - // getSharedPreferences("questionnaire", MODE_PRIVATE).getInt("apetite", 0); - // getSharedPreferences("questionnaire", MODE_PRIVATE).edit().putInt("apetite", 1).apply(); - - Date c = Calendar.getInstance().getTime(); SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy"); final String currentDate = df.format(c); - getSharedPreferences("date", MODE_PRIVATE).getString("startingDate", ""); getSharedPreferences("date", MODE_PRIVATE).edit().putString("startingDate", currentDate).apply(); - String participantID = getSharedPreferences("name", MODE_PRIVATE).getString("participantID", "nothing"); - - if (participantID.contains("B") || participantID.contains("b")) { - startActivity(intentB); - } else { - startActivity(intent); - } + startActivity(new Intent(this, AllPages.class)); final double finalMood = mood; @@ -232,8 +215,6 @@ public class QInitial extends AppCompatActivity { Report rep = new Report(userDatabase, getApplicationContext()); rep.save(username, true, getSharedPreferences("consent", MODE_PRIVATE).getString("consent", "nothing")); - // ArrayList<String> diary_comments = new ArrayList<String>(); - // diary_comments.add(""); String diary_comments = "gcm gcm gcm gcm gcm gcm gcm gcm gcm gcm gcm gcm gcm gcm gcm gcm"; getSharedPreferences("diary", MODE_PRIVATE).edit().putString("diary", diary_comments).apply(); String experiments = "No experiment for the initial day."; @@ -242,8 +223,6 @@ public class QInitial extends AppCompatActivity { }).start(); - String moods_string = getApplicationContext().getSharedPreferences("moods", MODE_PRIVATE).getString("moods", ""); - String[] moods = new String[0]; ArrayList<String> moodsArrayList = new ArrayList<String>(); @@ -258,18 +237,9 @@ public class QInitial extends AppCompatActivity { } getApplicationContext().getSharedPreferences("moods", MODE_PRIVATE).edit().putString("moods", sb.toString()).apply(); - getSharedPreferences("exp", MODE_PRIVATE).getString("picked", "picked"); getSharedPreferences("exp", MODE_PRIVATE).edit().putString("picked", "picked").apply(); - getSharedPreferences("expB", MODE_PRIVATE).getString("pickedB", "pickedB"); - getSharedPreferences("expB", MODE_PRIVATE).edit().putString("pickedB", "pickedB").apply(); } } -/* - public void onBackPressed() { - Intent intent = new Intent(this, MainMenu.class); - startActivity(intent); - finish(); - }*/ } diff --git a/app/src/main/java/com/uos/admin/sleepbetter/QuestionnaireBroadcast.java b/app/src/main/java/com/uos/admin/sleepbetter/QuestionnaireBroadcast.java new file mode 100644 index 0000000..a9ddfa0 --- /dev/null +++ b/app/src/main/java/com/uos/admin/sleepbetter/QuestionnaireBroadcast.java @@ -0,0 +1,40 @@ +package com.uos.admin.sleepbetter; + +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.support.v4.app.NotificationCompat; + +import static android.content.Context.MODE_PRIVATE; +import static com.uos.admin.sleepbetter.AllPages.nextclass; + +public class QuestionnaireBroadcast extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + + + long when = System.currentTimeMillis(); + NotificationManager notificationManager = (NotificationManager) context + .getSystemService(Context.NOTIFICATION_SERVICE); + + Intent notificationIntent = new Intent(context, nextclass); + notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + + PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, + notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); + + + NotificationCompat.Builder mNotifyBuilder = new NotificationCompat.Builder(context, "13") + .setSmallIcon(R.drawable.pillow) + .setContentTitle("Questionnaire") + .setContentText("Remember to complete the daily questionnaire!") + .setAutoCancel(false) + .setWhen(when) + .setOngoing(true) + .setContentIntent(pendingIntent); + notificationManager.notify(20, mNotifyBuilder.build()); + + } + } \ No newline at end of file diff --git a/app/src/main/java/com/uos/admin/sleepbetter/Report.java b/app/src/main/java/com/uos/admin/sleepbetter/Report.java index 0099475..971e64c 100644 --- a/app/src/main/java/com/uos/admin/sleepbetter/Report.java +++ b/app/src/main/java/com/uos/admin/sleepbetter/Report.java @@ -35,170 +35,153 @@ public class Report { public void save(String user, Boolean isFirstTime, String consent) { - String filePath = ""; - String filePathTwo = ""; - String filePath2 = ""; - try { - - List<UserQuestionnaire> uq = database.daoAccess().fetchUserQuestionnaires(); - - filePath = context.getFilesDir().getPath().toString() + "/" + user + "_userQuestionnaire.csv"; - - File f = new File(filePath); - - - BufferedWriter bw = null; - bw = new BufferedWriter(new FileWriter(f)); - bw.write("Username, Date, How long, Awake, Earlier, Nights A Week, Quality, Impact mood, Impact activities, Impact general, Problem, mood, Demographics, \n"); - - for (int i = 0; i < uq.size(); i++) { - bw.append(uq.get(i).getUsername() + ", " + uq.get(i).getDate() + ", " + uq.get(i).getHowLong() + - ", " + uq.get(i).getAwake() + ", " + uq.get(i).getEarlier() + ", " + uq.get(0).getNightsAWeek() + - ", " + uq.get(i).getQuality() + ", " + uq.get(i).getImpactMood() + - ", " + uq.get(i).getImpactActivities() + ", " + uq.get(i).getImpactGeneral() + ", " + uq.get(0).getProblem() + ", " + - uq.get(i).getMood() + ", " + context.getSharedPreferences("demographics", MODE_PRIVATE).getString("demographics", "") + "\n"); - } - - bw.close(); - - if (!isFirstTime){ - - List<UserExperiment> ue = database.daoAccess().fetchUserExperiments(); - - filePathTwo = context.getFilesDir().getPath().toString() + "/" + user + "_userExperiment.csv"; - - File f2 = new File(filePathTwo); - - - BufferedWriter bw2 = null; - bw2 = new BufferedWriter(new FileWriter(f2)); - bw2.write("Username, Date, Experiment, L1 sunlight exposure, L1 half an hour, L1 captures sunlight, L2 app, L2 glasses, L3 bright, L3 TV, C1 when drink, C1 when sleep, C2 cups, C2 cans, C2 energy, C3 drink, C3 empty, S1 when sleep, S1 when wak, S2 when sleep, S2 when wake, S3 relaxed, S3 activity, S4 when sleep, Overall better, Demographics, \n"); - - for (int i = 0; i < ue.size(); i++) { - bw2.append(ue.get(i).getUsername() + ", " + ue.get(i).getDate() + ", " + ue.get(i).getExperiment() + - ", " + ue.get(i).getLightOneSunlightExposure() + ", " + ue.get(i).getLightOneHalfAnHour() + ", " + ue.get(i).getLightOneCapturesSunlight() + - ", " + ue.get(i).getLightTwoApp() + ", " + ue.get(i).getLightTwoGlasses() + - ", " + ue.get(i).getLightThreeBright() + ", " + ue.get(i).getLightThreeTV() + ", " + ue.get(i).getCaffeineOneWhenDrink() + ", " + - ue.get(i).getCaffeineOneWhenSleep() + ", " + ue.get(i).getCaffeineTwoCups() + ", " + ue.get(i).getCaffeineTwoCans() + ", " - + ue.get(i).getCaffeineTwoEnergy() + ", " + ue.get(i).getCaffeineThreeDrink() + ", " + ue.get(i).getCaffeineThreeEmpty() + ", " - + ue.get(i).getScheduleOneWhenSleep() + ", " + ue.get(i).getScheduleOneWhenWake() + ", " + ue.get(i).getScheduleTwoWhenSleep() + ", " - + ue.get(i).getScheduleTwoWhenWake() + ", " + ue.get(i).getScheduleThreeRelaxed() + ", " + ue.get(i).getScheduleThreeActivity() + ", " - + ue.get(i).getScheduleFourWhenSleep() + ", " + ue.get(i).getOverallBetter() + ", " + context.getSharedPreferences("demographics", MODE_PRIVATE).getString("demographics", "") + "\n"); - } - - bw2.close(); - } - - List<UserDiary> ud = database.daoAccess().fetchDiary(); - - filePath2 = context.getFilesDir().getPath().toString() + "/" + user + "_userDiary.csv"; - - File f2 = new File(filePath2); - - - BufferedWriter bw2 = null; - bw2 = new BufferedWriter(new FileWriter(f2)); - bw2.write("Username, Date, Comment, \n"); - - for (int i = 0; i < ud.size(); i++) { - bw2.append(ud.get(i).getUsername() + ", " + ud.get(i).getDate() + ", " + ud.get(i).getComment() + "\n"); - } - - bw2.close(); - - - - } catch (IOException e) { - e.printStackTrace(); + List<UserQuestionnaire> uq = database.daoAccess().fetchUserQuestionnaires(); + + + String stats = ""; + + String date = ""; + String how_long = ""; + String awake = ""; + String earlier = ""; + String nightsAWeek = String.valueOf(uq.get(0).getNightsAWeek()); + String quality = ""; + String impact_mood = ""; + String impact_activities = ""; + String impact_general = ""; + String problem = String.valueOf(uq.get(0).getProblem()); + String mood = ""; + String demographics = context.getSharedPreferences("demographics", MODE_PRIVATE).getString("demographics", ""); + for (int i = 0; i < uq.size(); i++) { + date += String.valueOf(uq.get(i).getDate()) + ", "; + how_long += String.valueOf(uq.get(i).getHowLong()) + ", "; + awake += String.valueOf(uq.get(i).getAwake()) + ", "; + earlier += String.valueOf(uq.get(i).getEarlier()) + ", "; + quality += String.valueOf(uq.get(i).getQuality()) + ", "; + impact_mood += String.valueOf(uq.get(i).getImpactMood()) + ", "; + impact_activities += String.valueOf(uq.get(i).getImpactActivities()) + ", "; + impact_general += String.valueOf(uq.get(i).getImpactGeneral()) + ", "; + mood += String.valueOf(uq.get(i).getMood()) + ", "; } - - final String username = "gcm1y18"; - final String password = "experimentUK2"; - - Properties props = new Properties(); - props.put("mail.smtp.auth", true); - props.put("mail.smtp.starttls.enable", true); - props.put("mail.smtp.host", "smtp.soton.ac.uk"); - props.put("mail.smtp.port", "25"); - props.put("mail.smtp.EnableSSL.enable", "true"); - props.put("mail.smtp.ssl.trust", "smtp.soton.ac.uk"); - - Session session = Session.getInstance(props, new javax.mail.Authenticator() { - protected PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication(username, password); + stats += "Username: " + uq.get(0).getUsername() + "/ " + + "Date: " + date + "/ " + + "How long: " + how_long + "/ " + + "Awake: " + awake + "/ " + + "Earlier: " + earlier + "/ " + + "Nights A Week: " + nightsAWeek + "/ " + + "Quality: " + quality + "/ " + + "Impact mood: " + impact_mood + "/ " + + "Impact activities: " + impact_activities + "/ " + + "Impact general: " + impact_general + "/ " + + "Problem: " + problem + "/ " + + "Mood: " + mood + "/ " + + "Demographics: " + demographics + "/ "; + + + String experimentsList = ""; + + if (!isFirstTime) { + + List<UserExperiment> ue = database.daoAccess().fetchUserExperiments(); + + + String date2 = ""; + String experiment2 = ""; + String l1_1 = ""; + String l1_2 = ""; + String l1_3 = ""; + String l2_1 = ""; + String l2_2 = ""; + String l3_1 = ""; + String l3_2 = ""; + String c1_1 = ""; + String c1_2 = ""; + String c2_1 = ""; + String c2_2 = ""; + String c2_3 = ""; + String c3_1 = ""; + String c3_2 = ""; + String s1_1 = ""; + String s1_2 = ""; + String s2_1 = ""; + String s2_2 = ""; + String s3_1 = ""; + String s3_2 = ""; + String s4_1 = ""; + String overall_better = ""; + + for (int i = 0; i < ue.size(); i++) { + + date2 += String.valueOf(ue.get(i).getDate()) + ", "; + experiment2 += String.valueOf(ue.get(i).getExperiment()) + ", "; + l1_1 += String.valueOf(ue.get(i).getLightOneSunlightExposure()) + ", "; + l1_2 += String.valueOf(ue.get(i).getLightOneHalfAnHour()) + ", "; + l1_3 += String.valueOf(ue.get(i).getLightOneCapturesSunlight()) + ", "; + l2_1 += String.valueOf(ue.get(i).getLightTwoApp()) + ", "; + l2_2 += String.valueOf(ue.get(i).getLightTwoGlasses()) + ", "; + l3_1 += String.valueOf(ue.get(i).getLightThreeBright()) + ", "; + l3_2 += String.valueOf(ue.get(i).getLightThreeTV()) + ", "; + c1_1 += String.valueOf(ue.get(i).getCaffeineOneWhenDrink()) + ", "; + c1_2 += String.valueOf(ue.get(i).getCaffeineOneWhenSleep()) + ", "; + c2_1 += String.valueOf(ue.get(i).getCaffeineTwoCups()) + ", "; + c2_2 += String.valueOf(ue.get(i).getCaffeineTwoCans()) + ", "; + c2_3 += String.valueOf(ue.get(i).getCaffeineTwoEnergy()) + ", "; + c3_1 += String.valueOf(ue.get(i).getCaffeineThreeDrink()) + ", "; + c3_2 += String.valueOf(ue.get(i).getCaffeineThreeEmpty()) + ", "; + s1_1 += String.valueOf(ue.get(i).getScheduleOneWhenSleep()) + ", "; + s1_2 += String.valueOf(ue.get(i).getScheduleOneWhenWake()) + ", "; + s2_1 += String.valueOf(ue.get(i).getScheduleTwoWhenSleep()) + ", "; + s2_2 += String.valueOf(ue.get(i).getScheduleTwoWhenWake()) + ", "; + s3_1 += String.valueOf(ue.get(i).getScheduleThreeRelaxed()) + ", "; + s3_2 += String.valueOf(ue.get(i).getScheduleThreeActivity()) + ", "; + s4_1 += String.valueOf(ue.get(i).getScheduleFourWhenSleep()) + ", "; + overall_better += String.valueOf(ue.get(i).getOverallBetter()) + ", "; } - }); - - try { - - Message message = new MimeMessage(session); - message.setFrom(new InternetAddress("GC.Muresan@soton.ac.uk")); - message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("GC.Muresan@soton.ac.uk")); - message.setSubject("Username: " + user + " / First time: " + isFirstTime + " / Consent for interview: " + consent); - message.setText("PFA"); - - - - Multipart multipart = new MimeMultipart(); - - - MimeBodyPart messageBodyPart = new MimeBodyPart(); - - messageBodyPart = new MimeBodyPart(); - - String file = filePath; - - File ff = new File(file); - String fileName = user + "_userQuestionnaire.csv"; - DataSource source = new FileDataSource(file); - messageBodyPart.setDataHandler(new DataHandler(source)); - messageBodyPart.setFileName(fileName); - multipart.addBodyPart(messageBodyPart); + experimentsList += "Username: " + uq.get(0).getUsername() + "/ " + + "Date: " + date2 + "/ " + + "Experiment: " + experiment2 + "/ " + + "L1 sunlight exposure: " + l1_1 + "/ " + + "L1 half an hour: " + l1_2 + "/ " + + "L1 captures sunlight: " + l1_3 + "/ " + + "L2 app: " + l2_1 + "/ " + + "L2 glasses: " + l2_2 + "/ " + + "L3 bright: " + l3_1 + "/ " + + "L3 TV: " + l3_2 + "/ " + + "C1 when drink: " + c1_1 + "/ " + + "C1 when sleep: " + c1_2 + "/ " + + "C2 cups: " + c2_1 + "/ " + + "C2 cans: " + c2_2 + "/ " + + "C2 energy: " + c2_3 + "/ " + + "C3 drink: " + c3_1 + "/ " + + "C3 empty: " + c3_2 + "/ " + + "S1 when sleep: " + s1_1 + "/ " + + "S1 when wake: " + s1_2 + "/ " + + "S2 when sleep: " + s2_1 + "/ " + + "S2 when wake: " + s2_2 + "/ " + + "S3 relaxed: " + s3_1 + "/ " + + "S3 activity: " + s3_2 + "/ " + + "S4 when sleep: " + s4_1 + "/ " + + "Overall better: " + overall_better + "/ "; - if (!isFirstTime){ - MimeBodyPart messageBodyPartTwo = new MimeBodyPart(); - - messageBodyPartTwo = new MimeBodyPart(); - - String fileTwo = filePathTwo; - - File ff2 = new File(fileTwo); - String fileNameTwo = user + "_userExperiment.csv"; - DataSource sourceTwo = new FileDataSource(fileTwo); - messageBodyPartTwo.setDataHandler(new DataHandler(sourceTwo)); - messageBodyPartTwo.setFileName(fileNameTwo); - - multipart.addBodyPart(messageBodyPartTwo); - } - - MimeBodyPart messageBodyPartThree = new MimeBodyPart(); - - messageBodyPartThree = new MimeBodyPart(); - - String fileThree = filePath2; - - File ff3 = new File(fileThree); - String fileNameThree = user + "_userDiary.csv"; - DataSource source3 = new FileDataSource(fileThree); - messageBodyPartThree.setDataHandler(new DataHandler(source3)); - messageBodyPartThree.setFileName(fileNameThree); - - multipart.addBodyPart(messageBodyPartThree); + } + stats += experimentsList; + List<UserDiary> ud = database.daoAccess().fetchDiary(); - message.setContent(multipart); - System.out.println("Sending"); + String date3 = ""; + String comment = String.valueOf(uq.get(0).getProblem()); + for (int i = 0; i < ud.size(); i++) { + date3 += String.valueOf(ud.get(i).getDate()) + ", "; + comment += String.valueOf(ud.get(i).getComment()) + ", "; - Transport.send(message); + } + stats += "Date: " + date3 + "/ " + + "Comment: " + comment; - System.out.println("Done"); - } catch (MessagingException e) { - e.printStackTrace(); - } } } diff --git a/app/src/main/java/com/uos/admin/sleepbetter/Settings.java b/app/src/main/java/com/uos/admin/sleepbetter/Settings.java new file mode 100644 index 0000000..53c4528 --- /dev/null +++ b/app/src/main/java/com/uos/admin/sleepbetter/Settings.java @@ -0,0 +1,31 @@ +package com.uos.admin.sleepbetter; + +import android.content.Intent; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.Button; + +public class Settings extends AppCompatActivity { + + protected void onCreate(Bundle savedInstanceState) { + + + super.onCreate(savedInstanceState); + setContentView(R.layout.act_notice); + + + Button button = (Button) findViewById(R.id.submitButton); + button.setOnClickListener(new View.OnClickListener() { + + public void onClick(View v) { + + Intent intent = new Intent(getApplicationContext(), QInitial.class); + + startActivity(intent); + } + + }); + + } +} diff --git a/app/src/main/java/com/uos/admin/sleepbetter/Update.java b/app/src/main/java/com/uos/admin/sleepbetter/Update.java index 6260774..d1eef05 100644 --- a/app/src/main/java/com/uos/admin/sleepbetter/Update.java +++ b/app/src/main/java/com/uos/admin/sleepbetter/Update.java @@ -3,9 +3,19 @@ package com.uos.admin.sleepbetter; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Toast; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; + +import static android.content.Context.MODE_PRIVATE; public class Update extends Fragment { @@ -17,4 +27,110 @@ public class Update extends Fragment { return helpView; } + + private boolean checkIfAllowsQuestionnaire(){ + + Calendar calendar1 = Calendar.getInstance(); + SimpleDateFormat formatter1 = new SimpleDateFormat("HH:mm"); + String currentHour = formatter1.format(calendar1.getTime()); + + SimpleDateFormat formatter2 = new SimpleDateFormat("dd-MMM-yyyy"); + String currentDate = formatter2.format(calendar1.getTime()); + + + String startingDate = getActivity().getApplicationContext().getSharedPreferences("date", MODE_PRIVATE).getString("startingDate", ""); + + Date date1 = null; + Date date2 = null; + + SimpleDateFormat dates = new SimpleDateFormat("dd-MMM-yyyy"); + + //Setting dates + try { + date1 = dates.parse(currentDate); + date2 = dates.parse(startingDate); + } catch (ParseException e) { + e.printStackTrace(); + } + + Calendar c1 = Calendar.getInstance(); + c1.setTime(date1); + + Calendar c2 = Calendar.getInstance(); + c2.setTime(date2); + + int shouldBe = c1.get(Calendar.DAY_OF_YEAR) - c2.get(Calendar.DAY_OF_YEAR); + + + String experiments = getActivity().getApplicationContext().getSharedPreferences("experiments", MODE_PRIVATE).getString("experiments", ""); + + String[] experimentsArray = experiments.split("gcm"); + + System.out.println(experimentsArray.length); + if (getActivity().getApplicationContext().getSharedPreferences("experiments", MODE_PRIVATE).getString("experiments", "").equals("No experiment for the initial day.") && shouldBe == 0) { + Toast.makeText(getActivity().getApplicationContext(), "You are not allowed to fill in today's questionnaire. Choose an experiment if you haven't.", Toast.LENGTH_LONG).show(); + return false; + } else if (currentHour.compareTo("18:59") < 0) { + Toast.makeText(getActivity().getApplicationContext(), "You are not allowed to fill in today's questionnaire yet. Come back at 19:00.", Toast.LENGTH_LONG).show(); + + return false; + } else if (experimentsArray.length - shouldBe >= 1) { + Toast.makeText(getActivity().getApplicationContext(), "You are not allowed to fill in today's questionnaire. Come back tomorrow.", Toast.LENGTH_LONG).show(); + return false; + } else { + return true; + } + + } + + private boolean isViewShown = false; + + @Override + public void setUserVisibleHint(boolean isVisibleToUser) { + super.setUserVisibleHint(isVisibleToUser); + if (getView() != null) { + isViewShown = true; + loadPageDataProcessing(); + } else { + isViewShown = false; + } + } + + public void loadPageDataProcessing(){ + FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); + + String experiment = getActivity().getApplicationContext().getSharedPreferences("name", MODE_PRIVATE).getString("experiment", "nothing"); + + if (checkIfAllowsQuestionnaire()) { + + if (experiment.equals(getString(R.string.firstLight))) { + fragmentTransaction.replace(R.id.content_frame, new Update_Light_Bright()); + } else if (experiment.equals(getString(R.string.secondLight))) { + fragmentTransaction.replace(R.id.content_frame, new Update_Light_Glasses()); + } else if (experiment.equals(getString(R.string.thirdLight))) { + fragmentTransaction.replace(R.id.content_frame, new Update_Light_TurnOffBright()); + } else if (experiment.equals(getString(R.string.firstCaffeine))) { + fragmentTransaction.replace(R.id.content_frame, new Update_Caffeine_6hours()); + } else if (experiment.equals(getString(R.string.secondCaffeine))) { + fragmentTransaction.replace(R.id.content_frame, new Update_Caffeine_limit()); + } else if (experiment.equals(getString(R.string.thirdCaffeine))) { + fragmentTransaction.replace(R.id.content_frame, new Update_Caffeine_Empty()); + } else if (experiment.equals(getString(R.string.firstSchedule))) { + fragmentTransaction.replace(R.id.content_frame, new Update_Schedule_SameTime()); + } else if (experiment.equals(getString(R.string.secondSchedule))) { + fragmentTransaction.replace(R.id.content_frame, new Update_Schedule_7hours()); + } else if (experiment.equals(getString(R.string.thirdSchedule))) { + fragmentTransaction.replace(R.id.content_frame, new Update_Schedule_Relax()); + } else if (experiment.equals(getString(R.string.fourthSchedule))) { + fragmentTransaction.replace(R.id.content_frame, new Update_Schedule_Midnight()); + } else { + fragmentTransaction.replace(R.id.content_frame, new Update()); + } + + fragmentTransaction.addToBackStack(null); + fragmentTransaction.commit(); + getFragmentManager().executePendingTransactions(); + } + + } } diff --git a/app/src/main/java/com/uos/admin/sleepbetter/Update_Caffeine_6hours.java b/app/src/main/java/com/uos/admin/sleepbetter/Update_Caffeine_6hours.java index f1fbfd3..bc787ac 100644 --- a/app/src/main/java/com/uos/admin/sleepbetter/Update_Caffeine_6hours.java +++ b/app/src/main/java/com/uos/admin/sleepbetter/Update_Caffeine_6hours.java @@ -1,11 +1,12 @@ package com.uos.admin.sleepbetter; -import android.app.Fragment; -import android.app.FragmentManager; + import android.arch.persistence.room.Room; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.constraint.ConstraintLayout; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/app/src/main/java/com/uos/admin/sleepbetter/Update_Caffeine_Empty.java b/app/src/main/java/com/uos/admin/sleepbetter/Update_Caffeine_Empty.java index da31068..1158bdb 100644 --- a/app/src/main/java/com/uos/admin/sleepbetter/Update_Caffeine_Empty.java +++ b/app/src/main/java/com/uos/admin/sleepbetter/Update_Caffeine_Empty.java @@ -1,7 +1,7 @@ package com.uos.admin.sleepbetter; -import android.app.Fragment; -import android.app.FragmentManager; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; import android.arch.persistence.room.Room; import android.os.Bundle; import android.support.annotation.Nullable; diff --git a/app/src/main/java/com/uos/admin/sleepbetter/Update_Caffeine_limit.java b/app/src/main/java/com/uos/admin/sleepbetter/Update_Caffeine_limit.java index 3020be7..758d16f 100644 --- a/app/src/main/java/com/uos/admin/sleepbetter/Update_Caffeine_limit.java +++ b/app/src/main/java/com/uos/admin/sleepbetter/Update_Caffeine_limit.java @@ -1,7 +1,7 @@ package com.uos.admin.sleepbetter; -import android.app.Fragment; -import android.app.FragmentManager; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; import android.arch.persistence.room.Room; import android.os.Bundle; import android.support.annotation.Nullable; diff --git a/app/src/main/java/com/uos/admin/sleepbetter/Update_Light_Bright.java b/app/src/main/java/com/uos/admin/sleepbetter/Update_Light_Bright.java index 3282b55..b8feb66 100644 --- a/app/src/main/java/com/uos/admin/sleepbetter/Update_Light_Bright.java +++ b/app/src/main/java/com/uos/admin/sleepbetter/Update_Light_Bright.java @@ -1,7 +1,7 @@ package com.uos.admin.sleepbetter; -import android.app.Fragment; -import android.app.FragmentManager; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; import android.arch.persistence.room.Room; import android.os.Bundle; import android.support.annotation.Nullable; diff --git a/app/src/main/java/com/uos/admin/sleepbetter/Update_Light_Glasses.java b/app/src/main/java/com/uos/admin/sleepbetter/Update_Light_Glasses.java index 37eb17e..cca3d77 100644 --- a/app/src/main/java/com/uos/admin/sleepbetter/Update_Light_Glasses.java +++ b/app/src/main/java/com/uos/admin/sleepbetter/Update_Light_Glasses.java @@ -1,7 +1,7 @@ package com.uos.admin.sleepbetter; -import android.app.Fragment; -import android.app.FragmentManager; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; import android.arch.persistence.room.Room; import android.os.Bundle; import android.support.annotation.Nullable; diff --git a/app/src/main/java/com/uos/admin/sleepbetter/Update_Light_TurnOffBright.java b/app/src/main/java/com/uos/admin/sleepbetter/Update_Light_TurnOffBright.java index eaf670d..c323388 100644 --- a/app/src/main/java/com/uos/admin/sleepbetter/Update_Light_TurnOffBright.java +++ b/app/src/main/java/com/uos/admin/sleepbetter/Update_Light_TurnOffBright.java @@ -1,7 +1,7 @@ package com.uos.admin.sleepbetter; -import android.app.Fragment; -import android.app.FragmentManager; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; import android.arch.persistence.room.Room; import android.os.Bundle; import android.support.annotation.Nullable; diff --git a/app/src/main/java/com/uos/admin/sleepbetter/Update_Schedule_7hours.java b/app/src/main/java/com/uos/admin/sleepbetter/Update_Schedule_7hours.java index 701497b..64c3f9b 100644 --- a/app/src/main/java/com/uos/admin/sleepbetter/Update_Schedule_7hours.java +++ b/app/src/main/java/com/uos/admin/sleepbetter/Update_Schedule_7hours.java @@ -1,7 +1,7 @@ package com.uos.admin.sleepbetter; -import android.app.Fragment; -import android.app.FragmentManager; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; import android.arch.persistence.room.Room; import android.os.Bundle; import android.support.annotation.Nullable; diff --git a/app/src/main/java/com/uos/admin/sleepbetter/Update_Schedule_Midnight.java b/app/src/main/java/com/uos/admin/sleepbetter/Update_Schedule_Midnight.java index 494bda3..60435cb 100644 --- a/app/src/main/java/com/uos/admin/sleepbetter/Update_Schedule_Midnight.java +++ b/app/src/main/java/com/uos/admin/sleepbetter/Update_Schedule_Midnight.java @@ -1,7 +1,7 @@ package com.uos.admin.sleepbetter; -import android.app.Fragment; -import android.app.FragmentManager; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; import android.arch.persistence.room.Room; import android.os.Bundle; import android.support.annotation.Nullable; diff --git a/app/src/main/java/com/uos/admin/sleepbetter/Update_Schedule_Relax.java b/app/src/main/java/com/uos/admin/sleepbetter/Update_Schedule_Relax.java index cb68535..15fb242 100644 --- a/app/src/main/java/com/uos/admin/sleepbetter/Update_Schedule_Relax.java +++ b/app/src/main/java/com/uos/admin/sleepbetter/Update_Schedule_Relax.java @@ -1,7 +1,7 @@ package com.uos.admin.sleepbetter; -import android.app.Fragment; -import android.app.FragmentManager; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; import android.arch.persistence.room.Room; import android.os.Bundle; import android.support.annotation.Nullable; diff --git a/app/src/main/java/com/uos/admin/sleepbetter/Update_Schedule_SameTime.java b/app/src/main/java/com/uos/admin/sleepbetter/Update_Schedule_SameTime.java index 8dee114..e9ae530 100644 --- a/app/src/main/java/com/uos/admin/sleepbetter/Update_Schedule_SameTime.java +++ b/app/src/main/java/com/uos/admin/sleepbetter/Update_Schedule_SameTime.java @@ -1,7 +1,7 @@ package com.uos.admin.sleepbetter; -import android.app.Fragment; -import android.app.FragmentManager; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; import android.arch.persistence.room.Room; import android.os.Bundle; import android.support.annotation.Nullable; diff --git a/app/src/main/java/com/uos/admin/sleepbetter/WhatExperiments.java b/app/src/main/java/com/uos/admin/sleepbetter/WhatExperiments.java index a00746d..5b439b3 100644 --- a/app/src/main/java/com/uos/admin/sleepbetter/WhatExperiments.java +++ b/app/src/main/java/com/uos/admin/sleepbetter/WhatExperiments.java @@ -20,9 +20,6 @@ public class WhatExperiments extends AppCompatActivity { imageView = findViewById(R.id.imageView24); imageView.setImageResource(R.drawable.data); - imageView = findViewById(R.id.imageView25); - imageView.setImageResource(R.drawable.data); - Button button = (Button) findViewById(R.id.back); button.setOnClickListener(new View.OnClickListener() { @@ -39,7 +36,7 @@ public class WhatExperiments extends AppCompatActivity { private void goToThirdActivity() { - Intent intent = new Intent(this, MainMenu.class); + Intent intent = new Intent(this, AllPages.class); startActivity(intent); diff --git a/app/src/main/java/com/uos/admin/sleepbetter/WhatIsSleep.java b/app/src/main/java/com/uos/admin/sleepbetter/WhatIsSleep.java index 0b7a235..ecc0600 100644 --- a/app/src/main/java/com/uos/admin/sleepbetter/WhatIsSleep.java +++ b/app/src/main/java/com/uos/admin/sleepbetter/WhatIsSleep.java @@ -38,15 +38,9 @@ public class WhatIsSleep extends AppCompatActivity { String participantID = getSharedPreferences("name", MODE_PRIVATE).getString("participantID", "nothing"); - if (participantID.contains("B") || participantID.contains("b")){ - Intent intent = new Intent(this, B_MainMenu.class); + Intent intent = new Intent(this, AllPages.class); startActivity(intent); - } else { - Intent intent = new Intent(this, MainMenu.class); - - startActivity(intent); - } } diff --git a/app/src/main/res/layout/act_b_what_experiments.xml b/app/src/main/res/layout/act_b_what_experiments.xml deleted file mode 100644 index 7038d8e..0000000 --- a/app/src/main/res/layout/act_b_what_experiments.xml +++ /dev/null @@ -1,171 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:app="http://schemas.android.com/apk/res-auto" - xmlns:tools="http://schemas.android.com/tools" - android:layout_width="match_parent" - android:layout_height="match_parent" - tools:context=".FirstPage"> - - <ScrollView - android:id="@+id/ScrollViewQuestionnaire" - style="@android:style/Widget.Material.ScrollView" - android:layout_width="match_parent" - android:layout_height="0dp" - android:layout_marginBottom="8dp" - android:layout_marginEnd="8dp" - android:layout_marginStart="8dp" - android:layout_marginTop="8dp" - android:fillViewport="true" - android:scrollbarStyle="insideOverlay" - android:visibility="visible" - app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintHorizontal_bias="1.0" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@+id/topView" - app:layout_constraintVertical_bias="0.0" - tools:targetApi="lollipop"> - - <FrameLayout - android:id="@+id/FrameForScrollView" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_marginBottom="8dp" - android:layout_marginEnd="8dp" - android:layout_marginLeft="8dp" - android:layout_marginRight="8dp" - android:layout_marginStart="8dp" - android:layout_marginTop="8dp" - app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toEndOf="@+id/ScrollViewQuestionnaire" - app:layout_constraintStart_toStartOf="@+id/ScrollViewQuestionnaire" - app:layout_constraintTop_toTopOf="@+id/ScrollViewQuestionnaire"> - - <android.support.constraint.ConstraintLayout - android:layout_width="match_parent" - android:layout_height="wrap_content" - tools:layout_editor_absoluteX="8dp" - tools:layout_editor_absoluteY="0dp"> - - - <EditText - android:id="@+id/sleepHygieneTitle" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_marginEnd="8dp" - android:layout_marginStart="8dp" - android:clickable="false" - android:cursorVisible="false" - android:ems="10" - android:focusable="false" - android:focusableInTouchMode="false" - android:inputType="textPersonName" - android:text="@string/experimentTitle" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintHorizontal_bias="0.0" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent" /> - - <TextView - android:id="@+id/textView6" - android:layout_width="match_parent" - android:maxLines="30" - android:layout_height="100dp" - android:layout_marginEnd="8dp" - android:layout_marginStart="8dp" - android:layout_marginTop="8dp" - android:text="@string/experimentsB" - android:textAlignment="textStart" - android:textColor="@android:color/black" - app:autoSizeTextType="uniform" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@+id/sleepHygieneTitle" /> - - <Button - android:id="@+id/back" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginBottom="16dp" - android:layout_marginEnd="8dp" - android:layout_marginStart="8dp" - android:layout_marginTop="8dp" - android:text="@string/backButton" - app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@+id/textView9" /> - - <ImageView - android:id="@+id/imageView23" - android:layout_width="133dp" - android:layout_height="133dp" - android:layout_marginEnd="8dp" - android:layout_marginStart="8dp" - android:layout_marginTop="12dp" - app:layout_constraintEnd_toEndOf="@+id/textView6" - app:layout_constraintStart_toStartOf="@+id/textView6" - app:layout_constraintTop_toBottomOf="@+id/textView6" - app:srcCompat="@drawable/data" /> - - <TextView - android:id="@+id/textView9" - android:layout_width="match_parent" - android:layout_height="180dp" - android:layout_marginEnd="8dp" - android:maxLines="30" - android:layout_marginStart="8dp" - android:layout_marginTop="8dp" - android:text="@string/experiments2" - android:textColor="@android:color/black" - app:autoSizeTextType="uniform" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@+id/imageView23" /> - - - </android.support.constraint.ConstraintLayout> - </FrameLayout> - </ScrollView> - - <View - android:id="@+id/topView" - android:layout_width="match_parent" - android:layout_height="75dp" - tools:ignore="MissingConstraints" - tools:layout_editor_absoluteX="0dp" - tools:layout_editor_absoluteY="0dp" /> - - <TextView - android:id="@+id/welcomeTitle" - android:layout_width="258dp" - android:layout_height="wrap_content" - android:layout_marginBottom="8dp" - android:layout_marginEnd="8dp" - android:layout_marginStart="8dp" - android:layout_marginTop="8dp" - android:text="@string/whatExeriments" - android:textAllCaps="false" - android:textColor="@android:color/black" - android:textSize="20sp" - android:textStyle="bold" - app:layout_constraintBottom_toBottomOf="@+id/topView" - app:layout_constraintEnd_toStartOf="@+id/logoPlace" - app:layout_constraintStart_toStartOf="@+id/topView" - app:layout_constraintTop_toTopOf="@+id/topView" - app:layout_constraintVertical_bias="0.0" /> - - <ImageView - android:id="@+id/logoPlace" - android:layout_width="91dp" - android:layout_height="81dp" - android:layout_marginBottom="8dp" - android:layout_marginEnd="8dp" - android:layout_marginTop="8dp" - android:contentDescription="@string/desc" - app:layout_constraintBottom_toBottomOf="@+id/topView" - app:layout_constraintEnd_toEndOf="@+id/topView" - app:layout_constraintTop_toTopOf="@+id/topView" - app:srcCompat="@drawable/data" /> - -</android.support.constraint.ConstraintLayout> \ No newline at end of file diff --git a/app/src/main/res/layout/act_current_xperiment.xml b/app/src/main/res/layout/act_current_xperiment.xml new file mode 100644 index 0000000..742f215 --- /dev/null +++ b/app/src/main/res/layout/act_current_xperiment.xml @@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="utf-8"?> +<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + tools:context=".FirstPage"> + + <TextView + android:id="@+id/welcomeTitle" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginStart="8dp" + android:layout_marginTop="16dp" + android:layout_marginEnd="8dp" + android:text="My Experiment" + android:textAllCaps="false" + android:textColor="@android:color/black" + android:textSize="30sp" + android:textStyle="bold" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + + <Button + android:id="@+id/submitButton" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginStart="8dp" + android:layout_marginEnd="8dp" + android:layout_marginBottom="16dp" + android:text="@string/backButton" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" /> + + <TextView + android:id="@+id/descriptionID" + android:layout_width="408dp" + android:layout_height="360dp" + android:layout_marginTop="20dp" + android:maxLines="30" + android:text="Since you haven't chosen an experiment from the "Experiment" section yet, this section is unavailable." + android:textAlignment="center" + android:textColor="@android:color/black" + android:textSize="14sp" + app:autoSizeTextType="uniform" + app:layout_constraintHorizontal_bias="0.0" + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintTop_toBottomOf="@+id/welcomeTo3" /> + + <TextView + android:id="@+id/welcomeTo3" + android:layout_width="406dp" + android:layout_height="27dp" + android:layout_marginTop="40dp" + android:maxLines="30" + android:text="The experiment presumes:" + android:textAlignment="center" + android:textColor="@android:color/black" + android:textSize="14sp" + app:autoSizeTextType="uniform" + app:layout_constraintHorizontal_bias="0.0" + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintTop_toBottomOf="@+id/experimentTitleID" /> + + <TextView + android:id="@+id/experimentTitleID" + android:layout_width="393dp" + android:layout_height="44dp" + android:layout_marginTop="36dp" + android:maxLines="30" + android:text="NO CHOSEN EXPERIMENT" + android:textAlignment="center" + android:textColor="@android:color/black" + android:textSize="14sp" + android:textStyle="bold" + app:autoSizeTextType="uniform" + app:layout_constraintHorizontal_bias="0.111" + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintTop_toBottomOf="@+id/welcomeTitle" /> + +</android.support.constraint.ConstraintLayout> \ No newline at end of file diff --git a/app/src/main/res/layout/act_main_menu.xml b/app/src/main/res/layout/act_main_menu.xml index df09140..886b081 100644 --- a/app/src/main/res/layout/act_main_menu.xml +++ b/app/src/main/res/layout/act_main_menu.xml @@ -6,7 +6,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" - tools:context=".MainMenu"> + tools:context=".AllPages"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar_id" diff --git a/app/src/main/res/layout/act_menu.xml b/app/src/main/res/layout/act_menu.xml index b12a324..9fb1022 100644 --- a/app/src/main/res/layout/act_menu.xml +++ b/app/src/main/res/layout/act_menu.xml @@ -154,5 +154,18 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/imageView2" /> + <TextView + android:id="@+id/partID" + android:layout_width="236dp" + android:layout_height="0dp" + android:layout_marginStart="8dp" + android:layout_marginBottom="8dp" + android:text="Participant ID: " + android:textAlignment="center" + android:textColor="#000000" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" /> + </android.support.constraint.ConstraintLayout> </RelativeLayout> \ No newline at end of file diff --git a/app/src/main/res/layout/act_notice.xml b/app/src/main/res/layout/act_notice.xml index 4ad65b2..a5b0d51 100644 --- a/app/src/main/res/layout/act_notice.xml +++ b/app/src/main/res/layout/act_notice.xml @@ -6,15 +6,6 @@ android:layout_height="match_parent" tools:context=".FirstPage"> - <FrameLayout - android:id="@+id/content_frame" - android:layout_width="match_parent" - android:layout_height="match_parent" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintHorizontal_bias="1.0" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent"/> - <TextView android:id="@+id/welcomeTo" android:layout_width="match_parent" @@ -45,7 +36,7 @@ android:textStyle="bold" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="@+id/content_frame" /> + app:layout_constraintTop_toTopOf="parent" /> <Button android:id="@+id/submitButton" diff --git a/app/src/main/res/layout/act_settings.xml b/app/src/main/res/layout/act_settings.xml new file mode 100644 index 0000000..4753e53 --- /dev/null +++ b/app/src/main/res/layout/act_settings.xml @@ -0,0 +1,307 @@ +<?xml version="1.0" encoding="utf-8"?> +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="#FFF" + android:clickable="true"> + + <android.support.constraint.ConstraintLayout + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <ScrollView + android:id="@+id/ScrollViewQuestionnaire" + style="@android:style/Widget.Material.ScrollView" + android:layout_width="match_parent" + android:layout_height="0dp" + android:layout_marginStart="8dp" + android:layout_marginEnd="8dp" + android:layout_marginBottom="8dp" + android:fillViewport="true" + android:scrollbarStyle="insideOverlay" + android:visibility="visible" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.0" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + tools:targetApi="lollipop"> + + <FrameLayout + android:id="@+id/FrameForScrollView" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginStart="8dp" + android:layout_marginLeft="8dp" + android:layout_marginTop="8dp" + android:layout_marginEnd="8dp" + android:layout_marginRight="8dp" + android:layout_marginBottom="8dp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="@+id/ScrollViewQuestionnaire" + app:layout_constraintStart_toStartOf="@+id/ScrollViewQuestionnaire" + app:layout_constraintTop_toTopOf="@+id/ScrollViewQuestionnaire"> + + <android.support.constraint.ConstraintLayout + android:layout_width="match_parent" + android:layout_height="1080dp" + tools:context=".FirstPage"> + + <Button + android:id="@+id/submitButton" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginStart="8dp" + android:layout_marginEnd="8dp" + android:layout_marginBottom="16dp" + android:text="Save/Back" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" /> + + <CheckBox + android:id="@+id/checkBox" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginStart="6dp" + android:layout_marginTop="36dp" + android:layout_marginEnd="278dp" + android:text="Disable all notifications" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.0" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/radioGroup" /> + + <EditText + android:id="@+id/yourName2" + android:layout_width="345dp" + android:layout_height="29dp" + android:layout_marginTop="16dp" + android:background="@drawable/text_input_border" + android:hint="@string/name" + android:inputType="" + android:textSize="18sp" + android:textStyle="italic" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.039" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/textView8" /> + + <RadioGroup + android:id="@+id/radioGroup" + android:layout_width="352dp" + android:layout_height="99dp" + android:layout_marginStart="8dp" + android:layout_marginTop="8dp" + android:layout_marginEnd="8dp" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.323" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/welcomeTo6"> + + <RadioButton + android:id="@+id/radioButton71" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="1 notification" /> + + <RadioButton + android:id="@+id/radioButton72" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="2 notifications" /> + + <RadioButton + android:id="@+id/radioButton70" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="3 notifications" /> + </RadioGroup> + + <TextView + android:id="@+id/welcomeTo2" + android:layout_width="365dp" + android:layout_height="42dp" + android:layout_marginTop="4dp" + android:maxLines="20" + android:text="We highly recommend filling in the questionnaire at the end of the day and NOT the day/morning after." + android:textAlignment="viewStart" + android:textColor="@android:color/black" + android:textSize="14sp" + app:autoSizeTextType="uniform" + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintTop_toBottomOf="@+id/textView14" /> + + <TextView + android:id="@+id/welcomeTo4" + android:layout_width="123dp" + android:layout_height="19dp" + android:layout_marginTop="56dp" + android:maxLines="20" + android:text="Available from" + android:textAlignment="viewStart" + android:textColor="@android:color/black" + android:textSize="14sp" + app:autoSizeTextType="uniform" + app:layout_constraintHorizontal_bias="0.036" + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintTop_toBottomOf="@+id/textView14" /> + + <TextView + android:id="@+id/welcomeTo6" + android:layout_width="123dp" + android:layout_height="19dp" + android:layout_marginTop="320dp" + android:maxLines="20" + android:text="Notification settings" + android:textAlignment="viewStart" + android:textColor="@android:color/black" + android:textSize="14sp" + app:autoSizeTextType="uniform" + app:layout_constraintHorizontal_bias="0.035" + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintTop_toBottomOf="@+id/textView14" /> + + <TextView + android:id="@+id/welcomeTo5" + android:layout_width="123dp" + android:layout_height="19dp" + android:layout_marginTop="120dp" + android:maxLines="20" + android:text="Until" + android:textAlignment="viewStart" + android:textColor="@android:color/black" + android:textSize="14sp" + app:autoSizeTextType="uniform" + app:layout_constraintHorizontal_bias="0.035" + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintTop_toBottomOf="@+id/textView14" /> + + <TextView + android:id="@+id/welcomeTitle" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginStart="8dp" + android:layout_marginTop="16dp" + android:layout_marginEnd="8dp" + android:text="SETTINGS" + android:textAllCaps="false" + android:textColor="@android:color/black" + android:textSize="30sp" + android:textStyle="bold" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + + <TextView + android:id="@+id/textView8" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="32dp" + android:text="Name" + android:textAlignment="viewStart" + android:textColor="#000000" + android:textSize="18sp" + android:textStyle="bold" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.027" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/welcomeTitle" /> + + <TextView + android:id="@+id/textView11" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="28dp" + android:text="Current Experiment" + android:textAlignment="viewStart" + android:textColor="#000000" + android:textSize="18sp" + android:textStyle="bold" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.04" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/yourName2" /> + + <TextView + android:id="@+id/textView13" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="164dp" + android:text="Notification Settings" + android:textAlignment="viewStart" + android:textColor="#000000" + android:textSize="18sp" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.041" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/welcomeTitle" /> + + <TextView + android:id="@+id/textView14" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="28dp" + android:text="Daily Questionnaire" + android:textAlignment="viewStart" + android:textColor="#000000" + android:textSize="18sp" + android:textStyle="bold" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.027" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/lastDrink2" /> + + <TextView + android:id="@+id/textView11" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="132dp" + android:text="7 PM" + android:textAlignment="viewStart" + android:textColor="#000000" + android:textSize="18sp" + android:textStyle="bold" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.026" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/lastDrink2" /> + + <TimePicker + android:id="@+id/lastDrink2" + android:layout_width="match_parent" + android:layout_height="146dp" + android:layout_marginStart="8dp" + android:layout_marginTop="16dp" + android:timePickerMode="spinner" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.0" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/textView13" /> + + <TimePicker + android:id="@+id/lastDrink3" + android:layout_width="match_parent" + android:layout_height="146dp" + android:layout_marginStart="8dp" + android:layout_marginTop="16dp" + android:timePickerMode="spinner" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.0" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/welcomeTo5" /> + + </android.support.constraint.ConstraintLayout> + + </FrameLayout> + </ScrollView> + + </android.support.constraint.ConstraintLayout> + +</RelativeLayout> \ No newline at end of file diff --git a/app/src/main/res/layout/act_welcome.xml b/app/src/main/res/layout/act_welcome.xml index 40144b1..e69c47d 100644 --- a/app/src/main/res/layout/act_welcome.xml +++ b/app/src/main/res/layout/act_welcome.xml @@ -6,22 +6,6 @@ android:layout_height="match_parent" tools:context=".FirstPage"> - <EditText - android:id="@+id/participantName" - android:layout_width="150dp" - android:layout_height="30dp" - android:layout_marginEnd="8dp" - android:layout_marginStart="8dp" - android:layout_marginTop="12dp" - android:background="@drawable/text_input_border" - android:hint="@string/participant" - android:inputType="" - android:textSize="18sp" - android:textStyle="italic" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@+id/yourName" /> - <TextView android:id="@+id/welcomeTo" android:layout_width="match_parent" @@ -38,6 +22,21 @@ app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/welcomeTitle" /> + <TextView + android:id="@+id/participantID" + android:layout_width="242dp" + android:layout_height="27dp" + android:layout_marginTop="16dp" + android:maxLines="20" + android:text="Participant ID:" + android:textAlignment="center" + android:textColor="@android:color/black" + android:textSize="14sp" + app:autoSizeTextType="uniform" + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintTop_toBottomOf="@+id/yourName" /> + <TextView android:id="@+id/welcomeTitle" android:layout_width="wrap_content" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 124cbba..1c8c157 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -88,64 +88,19 @@ <string name="s2.1">If you woke up one or more times during last night, how long are you awake in total?</string> <string name="s3.1">If your final wake-up time occurred before you intended to wake up, how much earlier was this?</string> <string name="s5.1">How would you rate the quality of last night\'s sleep?</string> - <string name="s6.1">How do you think last night\'s sleep impacted your mood, energy, or relationships?</string> - <string name="s7.1">How do you think last night\'s sleep impacted your concentration, productivity, or ability to stay awake?</string> - <string name="s8.1">How do you think last night\'s sleep impacted your life in general?</string> - - <string name="questionnaireHelp">First, how would you rate the following aspects of your sleep and daily experience? 1 represents the lowest and 5 the highest.</string> - <string name="questionnaireHelpSecond">For the question \"How quickly do you usually fall asleep?\", please bare in mind that 1 means \"as soon as getting into bed\", 2 is \"within 20 minutes\", 3 is \"up to one hour\", 4 is \"1/1.30 hours\" and 5 is \"more than that\". Also, for the \"How easily do you usually wake up?\", notice that 1 means \"waking up with no alarm\", 2 is \"using the alarm only sometimes\", 3 is \"using the alarm but I get up easily\", 4 is \"using the snooze button once\", 5 is \"using the snooze button more than once\".</string> - - <string name="questionnaireUsuallyHelpSecond">For the question \"How easily did you fall asleep last night?\", please bare in mind that 1 means \"as soon as got into bed\", 2 is \"within 20 minutes\", 3 is \"up to one hour\", 4 is \"1/1.30 hours\" and 5 is \"more than that\". Also, for the \"How easily did you wake up this morning?\", notice that 1 means \"woke up with no alarm\", 2 is \"used the alarm\", 3 is \"used the alarm and hit snooze\", 4 is \"used the snooze button more than once\", 5 is \"could not wake up even wih alarm\".</string> - - <string name="nocturnalTitle">Night-time</string> - <string name="timesWakingUp">How many times do you wake up per night in average?</string> - <string name="nightTerrorUsually">Do you ever have night terrors? If yes, how many times a week?</string> - <string name="beforeAfter">Before and after</string> - <string name="fallAsleepUsually">How quickly do you usually fall asleep?</string> - <string name="wakeUpUsually">How easily do you usually wake up?</string> - <string name="freshUsually">How fresh do you usually feel after you wake up?</string> - <string name="mood">Mood</string> - - <string name="happyUsually">How happy do you usually feel during the day?</string> - <string name="sadUsually">How sad do you usually feel during the day?</string> - <string name="sleepyUsually">How sleepy do you usually feel during the day?</string> - <string name="tiredUsually">How tired do you usually feel during the day?</string> - <string name="stressUsually">How stressed do you usually feel during the day?</string> - <string name="irritableUsually">How irritable do you usually feel during the day?</string> - <string name="actions">Actions</string> - <string name="concentrateUsually">How hard is for you to concentrate during the day?</string> - <string name="coordinateUsually">How hard is for you to coordinate your activities during the day?</string> - <string name="apetiteUsually">How would you usually rate your appetite during the day?</string> + <string name="s6.1">How do you think last night\'s sleep negatively impacted your mood, energy, or relationships?</string> + <string name="s7.1">How do you think last night\'s sleep negatively impacted your concentration, productivity, or ability to stay awake?</string> + <string name="s8.1">How do you think last night\'s sleep negatively impacted your life in general?</string> + <string name="comments">Do you have any other notes you wish to add into your Goal Diary?</string> <string name="firstNote">*First note*</string> <string name="yourNote">Your note...</string> - <string name="offquestionnaireHelp">How would you rate the following aspects of your day? 1 represents the lowest and 5 the highest.</string> - - <string name="offtimesWakingUp">How many times did you wake up last night?</string> - <string name="offnightTerrorUsually">How many night terrors did you have last night?</string> - <string name="offfallAsleepUsually">How easily did you fall asleep last night?</string> - <string name="offwakeUpUsually">How easily did you wake up this morning?</string> - <string name="offfreshUsually">How fresh did you feel after you woke up today?</string> - - <string name="offhappyUsually">How happy did you feel today?</string> - <string name="offsadUsually">How sad did you feel today?</string> - <string name="offsleepyUsually">How sleepy did you feel today?</string> - <string name="offtiredUsually">How tired did you feel today?</string> - <string name="offstressUsually">How stressed did you feel today?</string> - <string name="offirritableUsually">How irritable did you feel today?</string> - <string name="offconcentrateUsually">How hard was for you to concentrate today?</string> - <string name="offcoordinateUsually">How hard was for you to coordinate your activities today?</string> - <string name="offapetiteUsually">How would you rate your appetite for today?</string> - <string name="goalDiaryTitle">CURRENT STATE</string> <string name="goalDiaryTitlee">GOAL DIARY</string> - <!--<string name="greatText">GREAT! My name is Alex and I will do this experiment together with you. As your companion, I will reflect your mood:</string>--> - <string name="greatText1">GREAT! My name is Alex and I will do this experiment together with you. As your companion, I will reflect your mood. I can see you are ok at the moment. That is great! We will work together to keep it like this and even improve your state.</string> - <string name="greatText2">GREAT! My name is Alex and I will do this experiment together with you. As your companion, I will reflect your mood. I see that you feel blue. We will work together to make you feel better and you will see, it is not hard at all.</string> - <string name="pleaseInputGoal">Please input either a goal, a wish, or any note. You can return to this section later.</string> + <string name="pleaseInputGoal">Please input either a goal, a wish, or any note. You can return to this section later.</string> <string name="goalInput">Goal Diary input...</string> <string-array name="targetGraph"> <item>Falling asleep</item> @@ -191,12 +146,6 @@ <string name="title_activity_main_menu">MainMenu</string> - <string name="navigation_drawer_open">Open navigation drawer</string> - <string name="navigation_drawer_close">Close navigation drawer</string> - <string name="nav_header_title">Android Studio</string> - <string name="nav_header_subtitle">android.studio@android.com</string> - <string name="nav_header_desc">Navigation header</string> - <string name="factorsTitle">EXPERIMENTS</string> <string name="settingsTitle">Settings</string> <string name="preQues">PRE-QUESTIONNAIRE</string> @@ -219,26 +168,12 @@ <string name="caffeineCheck">Caffeine</string> - <string name="sleepSettingsTitle">Sleep Settings</string> - <string name="lightIntro">Here you can mark which experiments you wish to undertake in terms of the LIGHT factor. You can also choose your own personalised behavior by clicking on PERSONALISED and having access to information.</string> - <string name="lightTitle">LIGHT</string> + <string name="lightTitle">LIGHT</string> <string name="firstLight">Increase bright light exposure during the day</string> - <string name="secondLight">Wear glasses that block blue light during the night.</string> + <string name="secondLight">Wear glasses/a sleeping mask that block blue light during the night.</string> <string name="thirdLight">Turn off any bright lights 2 hours before going to bed (such as TV/the computer etc).</string> - <string name="personalised">PERSONALISED</string> - <string name="personalisedText">You currently have no personalised plan for this factor.</string> - - <string name="lightPersTitle">LIGHT - PERSONALISED PLAN</string> - - <string name="chatbotTitle">CHATBOT</string> - - - <string name="drugEffectsTitle">Drug Effects</string> - - - <string name="caffeineIntro">Here you can mark which experiments you wish to undertake in terms of the CAFFEINE factor. You can also choose your own personalised behavior by clicking on PERSONALISED and having access to information.</string> <string name="caffeineTitle">CAFFEINE</string> <string name="firstCaffeine">Do not drink caffeine within 6 hours before sleep</string> <string name="secondCaffeine">Limit yourself to 4 cups of coffees per day; 10 cans of coke/fanta; 2 energy drinks</string> @@ -264,7 +199,7 @@ <string name="moreInfo">More Information</string> <string name="dataTitle">DATA</string> - <string name="dataIntro">Here you will be able to look at personal data in terms of progress, changes, variations and so on!\nSingle value displays - looking at your current state;\nImprovements - where you will be able to see what fields could be improved;\nTimelines - looking at your progress through 3 different types of graphs. </string> + <string name="dataIntro">Here you will be able to look at personal data in terms of progress, changes, variations and so on!\nRatings - looking at your current state;\nImprovements - where you will be able to see what fields could be improved;\nTimelines - looking at your progress through 3 different types of graphs. </string> <string name="progressTitle">Improvements</string> <string name="timelineTitle">Timelines</string> <string name="singleValueDisplayTitle">Ratings</string> @@ -293,9 +228,9 @@ <string name="turnOffIntro">Your current experiment is: TURN OFF ANY BRIGHT LIGHT WITHIN 2 HOURS OF GOING TO SLEEP. Below you are asked to complete the questions on whether you followed the experiment.</string> <string name="turnOffLightQuestion">Did you turn off any bright lights in your room with 2 hours before going to bed?</string> - <string name="glassesIntro">Your current experiment is: WEAR GLASSES THAT BLOCK ANY LIGHT DURING THE NIGHT. Below you are asked to complete the questions on whether you followed the experiment.</string> + <string name="glassesIntro">Your current experiment is: WEAR GLASSES/A SLEEPING MASK THAT BLOCK ANY LIGHT DURING THE NIGHT. Below you are asked to complete the questions on whether you followed the experiment.</string> <string name="dayQuestion">Did you use the f.lx app on the computer during the day?</string> - <string name="nightQuestion">Did you use any glasses to block blue light during the night?</string> + <string name="nightQuestion">Did you use any glasses/sleeping mask to block blue light during the night?</string> <string name="stomachIntro">Your current experiment is: DO NOT DRINK CAFFEINE ON EMPTY STOMACH. Below you are asked to complete the questions on whether you followed the experiment.</string> <string name="drinkCaffeineQuestion">Did you drink any caffeine today?</string> diff --git a/build.gradle b/build.gradle index 9c3977b..f53f49f 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.2' + classpath 'com.android.tools.build:gradle:3.5.0' // NOTE: Do not place your application dependencies here; they belong diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e46a22c..712e02e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Aug 22 17:00:13 BST 2019 +#Sat Aug 24 15:05:39 BST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip -- GitLab