From d3cee8a067536c798e46e0030da28eae1edcb86c Mon Sep 17 00:00:00 2001 From: George Muresan <georgecatalinmuresan@gmail.com> Date: Wed, 3 Jul 2019 18:35:14 +0100 Subject: [PATCH] changes --- .idea/misc.xml | 2 +- app/src/main/AndroidManifest.xml | 5 + .../example/admin/sleepbetter/B_MainMenu.java | 245 ++++++------------ .../admin/sleepbetter/CalendarPage.java | 19 +- .../com/example/admin/sleepbetter/Data.java | 2 +- .../example/admin/sleepbetter/Factors.java | 146 ++++++++--- .../example/admin/sleepbetter/FirstPage.java | 26 +- .../example/admin/sleepbetter/MainMenu.java | 85 +----- .../com/example/admin/sleepbetter/QFinal.java | 44 ++-- .../example/admin/sleepbetter/QInitial.java | 6 +- .../com/example/admin/sleepbetter/Report.java | 3 +- .../admin/sleepbetter/WhatIsSleep.java | 2 +- app/src/main/res/layout/act_consent.xml | 5 +- app/src/main/res/layout/act_ques_final.xml | 3 +- .../res/layout/act_update_caffeine_empty.xml | 4 +- 15 files changed, 274 insertions(+), 323 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index c0f68ed..99202cc 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -25,7 +25,7 @@ </value> </option> </component> - <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK"> + <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <output url="file://$PROJECT_DIR$/build/classes" /> </component> <component name="ProjectType"> diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ba8b864..a3cfd91 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -36,10 +36,15 @@ android:name=".MainMenu" android:label="@string/app_name" android:theme="@style/AppTheme.NoActionBar"></activity> + <activity + android:name=".B_MainMenu" + 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> </application> </manifest> \ No newline at end of file diff --git a/app/src/main/java/com/example/admin/sleepbetter/B_MainMenu.java b/app/src/main/java/com/example/admin/sleepbetter/B_MainMenu.java index d14536a..efe0f00 100644 --- a/app/src/main/java/com/example/admin/sleepbetter/B_MainMenu.java +++ b/app/src/main/java/com/example/admin/sleepbetter/B_MainMenu.java @@ -44,16 +44,6 @@ public class B_MainMenu extends AppCompatActivity implements NavigationView.OnNa setContentView(R.layout.act_b_menu); - -/* - String experimentss = "No experiment for the initial day.gcmNo experiment for the initial day.gcm gcm"; - - String[] s = experimentss.split("gcm"); - - System.out.println(s[0] + " RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR"); - System.out.println(s.length); - -*/ Date c = Calendar.getInstance().getTime(); SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy"); final String currentDate = df.format(c); @@ -81,98 +71,22 @@ public class B_MainMenu extends AppCompatActivity implements NavigationView.OnNa int shouldBe = c1.get(Calendar.DAY_OF_YEAR) - c2.get(Calendar.DAY_OF_YEAR); - final int finalShouldBe = shouldBe; - - new Thread(new Runnable() { - @Override - public void run() { - UserDatabase uDatabase = Room.databaseBuilder(getApplicationContext(), UserDatabase.class, DATABASE_NAME).fallbackToDestructiveMigration().build(); - int loggedIn = uDatabase.daoAccess().fetchUserQuestionnaires().size(); - - int misses = finalShouldBe -loggedIn; - - - if (misses >=1){ - - String moods_string = 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=1; i<misses; i++){ - // adaugam -1 in tabel - - UserQuestionnaire user = new UserQuestionnaire(); - String username = getApplicationContext().getSharedPreferences("name", MODE_PRIVATE).getString("participantID", "nothing"); user.setUsername(username); - user.setDate(currentDate); - user.setUsername(username); - user.setHowLong(-1); - user.setAwake(-1); - user.setEarlier(-1); - user.setNightsAWeek(-1); - user.setQuality(-1); - user.setImpactMood(-1); - user.setImpactActivities(-1); - user.setImpactGeneral(-1); - 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(); - - //setting mood value to -1 in shared preferences - - uDatabase.daoAccess().insertSingleUserQuestionnaire(user); - - moodsArrayList.add("-1"); - - Report rep = new Report(uDatabase, getApplicationContext()); - rep.save(username, false, getSharedPreferences("consent", MODE_PRIVATE).getString("consent", "nothing")); - } - - moods = moodsArrayList.toArray(moods); - - StringBuilder sb = new StringBuilder(); - 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(); - - } - - - - - - - - } - - //scoatem variabila days si verificam: daca se imparte la 5, si nu e locked, - }).start(); //update experiments - //including day 0 - shouldBe++; 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)); - experimentsArrayList.add(currentExperiment + "."); + for (int i=0; i< (shouldBe - experimentsArray.length); i++){ + experimentsArrayList.add(currentExperiment + "."); + } experimentsArray = experimentsArrayList.toArray(experimentsArray); @@ -214,7 +128,6 @@ public class B_MainMenu extends AppCompatActivity implements NavigationView.OnNa //NOTIFICATION DEMO this.createNotificationChannel(); this.setNotifications(); - this.setFirstSpecialNotification(); ///END NOTIFICATIONs Button button1 = (Button) findViewById(R.id.whatSleep); @@ -241,6 +154,75 @@ public class B_MainMenu extends AppCompatActivity implements NavigationView.OnNa }); + + String expStartDate = getSharedPreferences("date", MODE_PRIVATE).getString("startExperiment", ""); + + 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 { + date1 = dates.parse(currentDate); + date3 = dates.parse(expStartDate); + } catch (ParseException e) { + e.printStackTrace(); + } + + Calendar c3 = Calendar.getInstance(); + c3.setTime(date3); + + int experimentDaysDifference = c1.get(Calendar.DAY_OF_YEAR) - c2.get(Calendar.DAY_OF_YEAR); + + int difference = 5 - experimentDaysDifference; + + + remainedDaysText.setText("You have " + difference + " days left of the current experiment."); + + + if (expStartDate.equals(startingDate)) { + 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() { @@ -345,21 +327,6 @@ public class B_MainMenu extends AppCompatActivity implements NavigationView.OnNa 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(B_MainMenu.this, Broadcast2.class); - PendingIntent pendingIntent = PendingIntent.getBroadcast(B_MainMenu.this, 0, intent1, 0); - AlarmManager am1 = (AlarmManager) B_MainMenu.this.getSystemService(B_MainMenu.this.ALARM_SERVICE); - am1.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent); - - } //produce the required notifications private void setNotifications() { @@ -435,70 +402,4 @@ public class B_MainMenu extends AppCompatActivity implements NavigationView.OnNa } } - 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 = null; - int experiment = context.getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE).getInt("KEY_SAVED_RADIO_BUTTON_INDEX", 0); - - switch (experiment) { - case 1: //increase bright light exposure - notificationIntent = new Intent(context, Update_Light_Bright.class); - break; - case 2: //wear glasses that block blue light during the night - notificationIntent = new Intent(context, Update_Light_Glasses.class); - break; - case 3: // turn off any bright lights 2 hours before going to bed - notificationIntent = new Intent(context, Update_Light_TurnOffBright.class); - break; - case 5: // Do not drink caffeine within 6 hours - notificationIntent = new Intent(context, Update_Caffeine_6hours.class); - break; - case 6: // Limit yourself to 4 cups of coffees per day; 10 canss of - notificationIntent = new Intent(context, Update_Caffeine_limit.class); - break; - case 7: //Do not drink empty stomach - notificationIntent = new Intent(context, Update_Caffeine_Empty.class); - break; - case 9://Usually get up at the same time everyday, even on weekends - notificationIntent = new Intent(context, Update_Schedule_SameTime.class); - break; - case 10: // Sleep no lesss than 7 hours per night - notificationIntent = new Intent(context, Update_Schedule_7hours.class); - break; - case 11: //DO not go to bed unless you are tired. If you are not - notificationIntent = new Intent(context, Update_Schedule_Relax.class); - break; - case 12: //Go to sleep at 22:30 PM the latest - notificationIntent = new Intent(context, Update_Schedule_Midnight.class); - break; - } - - 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()); - - - } - } - } \ No newline at end of file diff --git a/app/src/main/java/com/example/admin/sleepbetter/CalendarPage.java b/app/src/main/java/com/example/admin/sleepbetter/CalendarPage.java index aa4f92f..35e7c4c 100644 --- a/app/src/main/java/com/example/admin/sleepbetter/CalendarPage.java +++ b/app/src/main/java/com/example/admin/sleepbetter/CalendarPage.java @@ -92,6 +92,7 @@ public class CalendarPage extends Fragment { //model date from 23-Jun-2019 too 2019-06-23 String dayForLoop = startingDate; + Calendar cal = Calendar.getInstance(); for (int i = 0; i <= shouldBe - 1; i++) { Date d1 = null; @@ -104,14 +105,15 @@ 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(diaries.length); + System.out.println(dateToAdd); HomeCollection.date_collection_arr.add(new HomeCollection(dateToAdd, experimentsArray[i], moods[i], diaries[i])); - Calendar cal = Calendar.getInstance(); + try { - cal.setTime(df.parse(startingDate)); + cal.setTime(df.parse(dayForLoop)); } catch (ParseException e) { e.printStackTrace(); } @@ -233,8 +235,9 @@ public class CalendarPage extends Fragment { //model date from 23-Jun-2019 too 2019-06-23 String dayForLoop = startingDate; + Calendar cal = Calendar.getInstance(); - for (int i = 0; i <= shouldBe -1 ; i++) { + for (int i = 0; i <= shouldBe - 1; i++) { Date d1 = null; try { d1=new SimpleDateFormat("dd-MMM-yyyy").parse(dayForLoop); @@ -245,11 +248,15 @@ 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])); - Calendar cal = Calendar.getInstance(); + try { - cal.setTime(df.parse(startingDate)); + cal.setTime(df.parse(dayForLoop)); } catch (ParseException e) { e.printStackTrace(); } diff --git a/app/src/main/java/com/example/admin/sleepbetter/Data.java b/app/src/main/java/com/example/admin/sleepbetter/Data.java index 543b4eb..98c49a1 100644 --- a/app/src/main/java/com/example/admin/sleepbetter/Data.java +++ b/app/src/main/java/com/example/admin/sleepbetter/Data.java @@ -288,7 +288,7 @@ public class Data extends Fragment implements AdapterView.OnItemSelectedListener @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.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(); diff --git a/app/src/main/java/com/example/admin/sleepbetter/Factors.java b/app/src/main/java/com/example/admin/sleepbetter/Factors.java index 806bb6a..915ac1f 100644 --- a/app/src/main/java/com/example/admin/sleepbetter/Factors.java +++ b/app/src/main/java/com/example/admin/sleepbetter/Factors.java @@ -55,7 +55,6 @@ public class Factors extends Fragment { radioGroup = (RadioGroup) factorsView.findViewById(R.id.experimentsGroup); if (!experiment.equals("nothing")){ - System.out.println("YESSSSSSSSSSSSSSS"); RadioButton savedCheckedRadioButton = (RadioButton)radioGroup.getChildAt(savedRadioIndex); savedCheckedRadioButton.setChecked(true); } @@ -138,8 +137,7 @@ public class Factors extends Fragment { e.printStackTrace(); } - System.out.println(date1); - System.out.println(date2); + Calendar c1 = Calendar.getInstance(); c1.setTime(date1); @@ -149,35 +147,111 @@ public class Factors extends Fragment { int differenceBetweenOldExperimentAndCurrent = c1.get(Calendar.DAY_OF_YEAR) - c2.get(Calendar.DAY_OF_YEAR); - if (differenceBetweenOldExperimentAndCurrent % 5 < 5 && !getActivity().getApplicationContext().getSharedPreferences("experiments", MODE_PRIVATE).getString("experiments", "").equals("No experiment for the initial day.")){ - 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(); - } else if (differenceBetweenOldExperimentAndCurrent % 5 == 0){ - if (Integer.valueOf(currentHour) < 19){ - 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(); + String participantID = getActivity().getApplicationContext().getSharedPreferences("name", MODE_PRIVATE).getString("participantID", "nothing"); - } else if (loggedIn % 5 != 1){ - 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(); + + 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(); + + + } else if (differenceBetweenOldExperimentAndCurrent == 0 && getActivity().getSharedPreferences("expB", MODE_PRIVATE).getString("pickedB", "").equals("newPickedB")){ + + 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){ + 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("expB", MODE_PRIVATE).getString("pickedB", "").equals("newPickedB")){ + + 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(); + + } + } + + /* + 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); } - } else { + 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 as 5 days have not passed yet.", Toast.LENGTH_LONG).show(); + 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(); + + }*/ + } + + + + + return factorsView; } @@ -243,7 +317,7 @@ public class Factors extends Fragment { for (int i = 0; i < radioGroup.getChildCount(); i++) { radioGroup.getChildAt(i).setEnabled(false); } - Intent intent = new Intent(getActivity().getApplicationContext(), MainMenu.class); + //update starting date Date c = Calendar.getInstance().getTime(); @@ -252,26 +326,26 @@ public class Factors extends Fragment { getActivity().getSharedPreferences("date", MODE_PRIVATE).getString("startExperiment", ""); getActivity().getSharedPreferences("date", MODE_PRIVATE).edit().putString("startExperiment", currentDate).apply(); - // - String experiments = getActivity().getSharedPreferences("experiments", MODE_PRIVATE).getString("experiments", ""); + 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 currentExperiment = getActivity().getApplicationContext().getSharedPreferences("name", MODE_PRIVATE).getString("experiment", "nothing"); + // - String[] experimentsArray = experiments.split("gcm"); + String participantID = getActivity().getApplicationContext().getSharedPreferences("name", MODE_PRIVATE).getString("participantID", "nothing"); - ArrayList<String> experimentsArrayList = new ArrayList<String>(Arrays.asList(experimentsArray)); - experimentsArrayList.add(currentExperiment + "."); + if (participantID.contains("B") || participantID.contains("b")){ + Intent intent = new Intent(getActivity().getApplicationContext(), B_MainMenu.class); - experimentsArray = experimentsArrayList.toArray(experimentsArray); - - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < experimentsArray.length; i++) { - sb.append(experimentsArray[i]).append("gcm"); - } - getActivity().getApplicationContext().getSharedPreferences("experiments", MODE_PRIVATE).edit().putString("experiments", sb.toString()).apply(); + startActivity(intent); + } else { + Intent intent = new Intent(getActivity().getApplicationContext(), MainMenu.class); startActivity(intent); + } + } }) .setNegativeButton("Back", new DialogInterface.OnClickListener() { diff --git a/app/src/main/java/com/example/admin/sleepbetter/FirstPage.java b/app/src/main/java/com/example/admin/sleepbetter/FirstPage.java index 390fdb4..7d21c4a 100644 --- a/app/src/main/java/com/example/admin/sleepbetter/FirstPage.java +++ b/app/src/main/java/com/example/admin/sleepbetter/FirstPage.java @@ -108,7 +108,7 @@ public class FirstPage extends AppCompatActivity { String participantID = getSharedPreferences("name", MODE_PRIVATE).getString("participantID", "nothing"); - if (participantID.contains("B")){ + if (participantID.contains("B") || participantID.contains("b")){ startActivity(new Intent(this, B_MainMenu.class)); } else { startActivity(new Intent(this, MainMenu.class)); @@ -126,6 +126,8 @@ public class FirstPage extends AppCompatActivity { private void goToSecondActivity() { + + if (nameBox.getText().toString().equals("")){ Toast.makeText(getApplicationContext(), "Please input your name", Toast.LENGTH_SHORT).show(); @@ -133,16 +135,24 @@ public class FirstPage extends AppCompatActivity { Toast.makeText(getApplicationContext(), "Please input your participant ID number", Toast.LENGTH_SHORT).show(); } else { - Intent intent = new Intent(this, Notice.class); - String name = nameBox.getText().toString(); - String participant = participantID.getText().toString(); + 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, Notice.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(); + + } - 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); } diff --git a/app/src/main/java/com/example/admin/sleepbetter/MainMenu.java b/app/src/main/java/com/example/admin/sleepbetter/MainMenu.java index 96dc54c..14178d7 100644 --- a/app/src/main/java/com/example/admin/sleepbetter/MainMenu.java +++ b/app/src/main/java/com/example/admin/sleepbetter/MainMenu.java @@ -13,7 +13,6 @@ import android.content.Context; import android.content.Intent; import android.os.Build; import android.os.Bundle; -import android.support.constraint.ConstraintLayout; import android.support.v4.app.NotificationCompat; import android.view.View; import android.support.design.widget.NavigationView; @@ -28,8 +27,6 @@ import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; -import org.w3c.dom.Text; - import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -47,14 +44,6 @@ public class MainMenu extends AppCompatActivity implements NavigationView.OnNavi setContentView(R.layout.act_menu); - - String moods_string = getApplicationContext().getSharedPreferences("moods", MODE_PRIVATE).getString("moods", ""); - - String[] moods = moods_string.split("gcm"); - - System.out.println("MOODS " + moods_string); - System.out.println(moods.length); - Date c = Calendar.getInstance().getTime(); SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy"); final String currentDate = df.format(c); @@ -90,6 +79,7 @@ public class MainMenu extends AppCompatActivity implements NavigationView.OnNavi UserDatabase uDatabase = Room.databaseBuilder(getApplicationContext(), UserDatabase.class, DATABASE_NAME).fallbackToDestructiveMigration().build(); int loggedIn = uDatabase.daoAccess().fetchUserQuestionnaires().size(); + int misses = finalShouldBe -loggedIn; @@ -101,7 +91,7 @@ public class MainMenu extends AppCompatActivity implements NavigationView.OnNavi ArrayList<String> moodsArrayList = new ArrayList<String>(Arrays.asList(moods)); - for (int i=1; i<misses; i++){ + for (int i=0; i<misses; i++){ // adaugam -1 in tabel UserQuestionnaire user = new UserQuestionnaire(); @@ -166,17 +156,12 @@ public class MainMenu extends AppCompatActivity implements NavigationView.OnNavi String[] experimentsArray = experiments.split("gcm"); - System.out.println(shouldBe); - System.out.println(experimentsArray.length); - System.out.println(shouldBe >= experimentsArray.length); - //+1 to include dy 0 - if ((shouldBe +1)> experimentsArray.length){ + 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++){ + for (int i=0; i< (shouldBe - experimentsArray.length); i++){ experimentsArrayList.add(currentExperiment + "."); } @@ -188,6 +173,7 @@ public class MainMenu extends AppCompatActivity implements NavigationView.OnNavi } getSharedPreferences("experiments", MODE_PRIVATE).edit().putString("experiments", sb.toString()).apply(); + } //context.getSharedPreferences("questionnaire", MODE_PRIVATE).edit().putBoolean("completed", false).apply(); @@ -432,28 +418,16 @@ public class MainMenu extends AppCompatActivity implements NavigationView.OnNavi String experiments = getSharedPreferences("experiments", MODE_PRIVATE).getString("experiments", ""); String[] experimentsArray = experiments.split("gcm"); - /* String[] copy = new String[2]; - copy[0] = experimentsArray[0]; - copy[1] = experimentsArray[1]; - experimentsArray = copy; - - 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(); - System.out.println(shouldBe); System.out.println(experimentsArray.length); - System.out.println(experimentsArray.length - shouldBe > 1);*/ - if (currentHour.compareTo("18:59") < 0) { + 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 (getApplicationContext().getSharedPreferences("experiments", MODE_PRIVATE).getString("experiments", "").equals("No experiment for the initial day.")) { - Toast.makeText(getApplicationContext(), "You are not allowed to fill in today's questionnaire. Come back after you choose an experiment.", Toast.LENGTH_LONG).show(); - return false; - } else if (experimentsArray.length - shouldBe > 1) { + } 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 { @@ -540,7 +514,6 @@ public class MainMenu extends AppCompatActivity implements NavigationView.OnNavi 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 @@ -597,42 +570,8 @@ public class MainMenu extends AppCompatActivity implements NavigationView.OnNavi NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); //AICIII - Intent notificationIntent = null; - int experiment = context.getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE).getInt("KEY_SAVED_RADIO_BUTTON_INDEX", 0); - - switch (experiment) { - case 1: //increase bright light exposure - notificationIntent = new Intent(context, Update_Light_Bright.class); - break; - case 2: //wear glasses that block blue light during the night - notificationIntent = new Intent(context, Update_Light_Glasses.class); - break; - case 3: // turn off any bright lights 2 hours before going to bed - notificationIntent = new Intent(context, Update_Light_TurnOffBright.class); - break; - case 5: // Do not drink caffeine within 6 hours - notificationIntent = new Intent(context, Update_Caffeine_6hours.class); - break; - case 6: // Limit yourself to 4 cups of coffees per day; 10 canss of - notificationIntent = new Intent(context, Update_Caffeine_limit.class); - break; - case 7: //Do not drink empty stomach - notificationIntent = new Intent(context, Update_Caffeine_Empty.class); - break; - case 9://Usually get up at the same time everyday, even on weekends - notificationIntent = new Intent(context, Update_Schedule_SameTime.class); - break; - case 10: // Sleep no lesss than 7 hours per night - notificationIntent = new Intent(context, Update_Schedule_7hours.class); - break; - case 11: //DO not go to bed unless you are tired. If you are not - notificationIntent = new Intent(context, Update_Schedule_Relax.class); - break; - case 12: //Go to sleep at 22:30 PM the latest - notificationIntent = new Intent(context, Update_Schedule_Midnight.class); - break; - } - + Intent notificationIntent = new Intent(context, MainMenu.class); + notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, diff --git a/app/src/main/java/com/example/admin/sleepbetter/QFinal.java b/app/src/main/java/com/example/admin/sleepbetter/QFinal.java index 17ca1a7..e4a80a1 100644 --- a/app/src/main/java/com/example/admin/sleepbetter/QFinal.java +++ b/app/src/main/java/com/example/admin/sleepbetter/QFinal.java @@ -93,12 +93,6 @@ public class QFinal extends Fragment { final int earlier = qGroup.indexOfChild(radioButton) +1; mood += earlier; - qGroup = questionnaireView.findViewById(R.id.q4Group); - qID = qGroup.getCheckedRadioButtonId(); - radioButton = qGroup.findViewById(qID); - final int nightsAWeek = qGroup.indexOfChild(radioButton) +1; - mood += nightsAWeek; - qGroup = questionnaireView.findViewById(R.id.q5Group); qID = qGroup.getCheckedRadioButtonId(); radioButton = qGroup.findViewById(qID); @@ -123,13 +117,8 @@ public class QFinal extends Fragment { final int impactGeneral = qGroup.indexOfChild(radioButton) +1; mood += impactGeneral; - qGroup = questionnaireView.findViewById(R.id.q9Group); - qID = qGroup.getCheckedRadioButtonId(); - radioButton = qGroup.findViewById(qID); - final int problem = qGroup.indexOfChild(radioButton) +1; - mood += problem; - mood = mood/9; + mood = mood/7; DecimalFormat formatting = new DecimalFormat("#.##"); mood = Double.parseDouble(formatting.format(mood)); @@ -137,11 +126,7 @@ public class QFinal extends Fragment { String participantID = getActivity().getApplicationContext().getSharedPreferences("name", MODE_PRIVATE).getString("participantID", "nothing"); - if (participantID.contains("B")){ - startActivity(new Intent(getActivity().getApplicationContext(), B_MainMenu.class)); - } else { - startActivity(new Intent(getActivity().getApplicationContext(), MainMenu.class)); - } + startActivity(new Intent(getActivity().getApplicationContext(), MainMenu.class)); Date c = Calendar.getInstance().getTime(); @@ -164,12 +149,12 @@ public class QFinal extends Fragment { user.setHowLong(howLong); user.setAwake(awake); user.setEarlier(earlier); - user.setNightsAWeek(nightsAWeek); + user.setNightsAWeek(-1); user.setQuality(quality); user.setImpactMood(impactMood); user.setImpactActivities(impactActivities); user.setImpactGeneral(impactGeneral); - user.setProblem(problem); + user.setProblem(-1); user.setMood(finalMood); getActivity().getApplicationContext().getSharedPreferences("questionnaire", MODE_PRIVATE).edit().putInt("howLong", howLong).apply(); @@ -206,6 +191,27 @@ public class QFinal extends Fragment { } getActivity().getApplicationContext().getSharedPreferences("moods", MODE_PRIVATE).edit().putString("moods", sb.toString()).apply(); + String experiments = getActivity().getApplicationContext().getSharedPreferences("experiments", MODE_PRIVATE).getString("experiments", ""); + + String[] experimentsArray = experiments.split("gcm"); + String currentExperiment = getActivity().getApplicationContext().getSharedPreferences("name", MODE_PRIVATE).getString("experiment", "nothing"); + + + ArrayList<String> experimentsArrayList = new ArrayList<String>(Arrays.asList(experimentsArray)); + experimentsArrayList.add(currentExperiment + "."); + + + experimentsArray = experimentsArrayList.toArray(experimentsArray); + + sb = new StringBuilder(); + for (int i = 0; i < experimentsArray.length; i++) { + sb.append(experimentsArray[i]).append("gcm"); + } + getActivity().getApplicationContext().getSharedPreferences("experiments", MODE_PRIVATE).edit().putString("experiments", sb.toString()).apply(); + + getActivity().getSharedPreferences("exp", MODE_PRIVATE).getString("picked", "picked"); + getActivity().getSharedPreferences("exp", MODE_PRIVATE).edit().putString("picked", "picked").apply(); + } public boolean isConnected() { diff --git a/app/src/main/java/com/example/admin/sleepbetter/QInitial.java b/app/src/main/java/com/example/admin/sleepbetter/QInitial.java index 4dc133c..185ca5e 100644 --- a/app/src/main/java/com/example/admin/sleepbetter/QInitial.java +++ b/app/src/main/java/com/example/admin/sleepbetter/QInitial.java @@ -178,7 +178,7 @@ public class QInitial extends AppCompatActivity { String participantID = getSharedPreferences("name", MODE_PRIVATE).getString("participantID", "nothing"); - if (participantID.contains("B")){ + if (participantID.contains("B") || participantID.contains("b")){ startActivity(intentB); } else { startActivity(intent); @@ -250,6 +250,10 @@ 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(); } /* diff --git a/app/src/main/java/com/example/admin/sleepbetter/Report.java b/app/src/main/java/com/example/admin/sleepbetter/Report.java index 39a6163..496c35b 100644 --- a/app/src/main/java/com/example/admin/sleepbetter/Report.java +++ b/app/src/main/java/com/example/admin/sleepbetter/Report.java @@ -113,7 +113,7 @@ public class Report { } final String username = "gcm1y18"; - final String password = "Ohmygoals2018"; + final String password = "experimentUK2"; Properties props = new Properties(); props.put("mail.smtp.auth", true); @@ -121,6 +121,7 @@ public class Report { 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() { diff --git a/app/src/main/java/com/example/admin/sleepbetter/WhatIsSleep.java b/app/src/main/java/com/example/admin/sleepbetter/WhatIsSleep.java index 6ace177..41f37c3 100644 --- a/app/src/main/java/com/example/admin/sleepbetter/WhatIsSleep.java +++ b/app/src/main/java/com/example/admin/sleepbetter/WhatIsSleep.java @@ -38,7 +38,7 @@ public class WhatIsSleep extends AppCompatActivity { String participantID = getSharedPreferences("name", MODE_PRIVATE).getString("participantID", "nothing"); - if (participantID.contains("B")){ + if (participantID.contains("B") || participantID.contains("b")){ Intent intent = new Intent(this, B_MainMenu.class); startActivity(intent); diff --git a/app/src/main/res/layout/act_consent.xml b/app/src/main/res/layout/act_consent.xml index e5c7ac7..4f5debf 100644 --- a/app/src/main/res/layout/act_consent.xml +++ b/app/src/main/res/layout/act_consent.xml @@ -98,7 +98,10 @@ <android.support.constraint.ConstraintLayout android:layout_width="match_parent" - android:layout_height="636dp" + android:layout_height="755dp" + android:layout_alignParentBottom="true" + android:layout_centerHorizontal="true" + android:layout_marginBottom="0dp" tools:layout_editor_absoluteX="8dp" tools:layout_editor_absoluteY="0dp"> diff --git a/app/src/main/res/layout/act_ques_final.xml b/app/src/main/res/layout/act_ques_final.xml index 2215cc7..470f88e 100644 --- a/app/src/main/res/layout/act_ques_final.xml +++ b/app/src/main/res/layout/act_ques_final.xml @@ -4,6 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + android:background="@android:color/white" tools:context=".SecondPage"> <View @@ -159,7 +160,7 @@ android:layout_height="43dp" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" - android:text="@string/nextButton" + android:text="@string/submitUpdate" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/q8Group" /> diff --git a/app/src/main/res/layout/act_update_caffeine_empty.xml b/app/src/main/res/layout/act_update_caffeine_empty.xml index 3dd4a91..5dac726 100644 --- a/app/src/main/res/layout/act_update_caffeine_empty.xml +++ b/app/src/main/res/layout/act_update_caffeine_empty.xml @@ -184,7 +184,7 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@+id/radioGroup" /> + app:layout_constraintTop_toBottomOf="@+id/radioGroup2" /> <EditText android:id="@+id/dayReview" @@ -289,7 +289,7 @@ app:layout_constraintTop_toBottomOf="@+id/activityGroup" /> <RadioGroup - android:id="@+id/radioGroup" + android:id="@+id/radioGroup2" android:layout_width="327dp" android:layout_height="128dp" android:layout_marginEnd="8dp" -- GitLab