diff --git a/.idea/misc.xml b/.idea/misc.xml index 37a750962da6f2b31810e85c8acae1081de7f58c..6630d507e4c25233f2c54720177f53625cb8d83b 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,44 @@ <?xml version="1.0" encoding="UTF-8"?> <project version="4"> + <component name="NullableNotNullManager"> + <option name="myDefaultNullable" value="org.jetbrains.annotations.Nullable" /> + <option name="myDefaultNotNull" value="androidx.annotation.NonNull" /> + <option name="myNullables"> + <value> + <list size="12"> + <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" /> + <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" /> + <item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" /> + <item index="3" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" /> + <item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" /> + <item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" /> + <item index="6" class="java.lang.String" itemvalue="android.annotation.Nullable" /> + <item index="7" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNullable" /> + <item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.Nullable" /> + <item index="9" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableDecl" /> + <item index="10" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableType" /> + <item index="11" class="java.lang.String" itemvalue="com.android.annotations.Nullable" /> + </list> + </value> + </option> + <option name="myNotNulls"> + <value> + <list size="11"> + <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" /> + <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" /> + <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" /> + <item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" /> + <item index="4" class="java.lang.String" itemvalue="androidx.annotation.NonNull" /> + <item index="5" class="java.lang.String" itemvalue="android.annotation.NonNull" /> + <item index="6" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNonNull" /> + <item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.NonNull" /> + <item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullDecl" /> + <item index="9" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullType" /> + <item index="10" class="java.lang.String" itemvalue="com.android.annotations.NonNull" /> + </list> + </value> + </option> + </component> <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> diff --git a/app/src/main/java/com/yearthreeproject/xbframework/ExperimentSurveyCreatorActivity.java b/app/src/main/java/com/yearthreeproject/xbframework/ExperimentSurveyCreatorActivity.java index 589208225fc9e6ad9306eb495143f27e861a0201..61cb15dc5fb2047b010123059e1df0bdb05e6e66 100644 --- a/app/src/main/java/com/yearthreeproject/xbframework/ExperimentSurveyCreatorActivity.java +++ b/app/src/main/java/com/yearthreeproject/xbframework/ExperimentSurveyCreatorActivity.java @@ -90,6 +90,154 @@ public class ExperimentSurveyCreatorActivity extends AppCompatActivity { scrollLayout.addView(newHR(4)); scrollLayout.addView(notificationLayout()); scrollLayout.addView(newHR(4)); + scrollLayout.addView(imageProcessingLayout()); + scrollLayout.addView(newHR(4)); + scrollLayout.addView(artefactImplementationLayout()); + scrollLayout.addView(newHR(4)); + scrollLayout.addView(audioProcessingLayout()); + scrollLayout.addView(newHR(4)); + scrollLayout.addView(videoProcessingLayout()); + scrollLayout.addView(newHR(4)); + } + + private View artefactImplementationLayout() { + final RelativeLayout artefactLayout = new RelativeLayout(this); + + TextView surveyTitle = new TextView(this); + surveyTitle.setText("Artefacts"); + surveyTitle.setId(uniqueID++); + + Switch surveyToggleSlider = new Switch(this); + surveyToggleSlider.setChecked(false); + + RelativeLayout.LayoutParams sliderAlignment = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + sliderAlignment.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); + sliderAlignment.addRule(RelativeLayout.ALIGN_PARENT_TOP); + + RelativeLayout.LayoutParams titleAlignment = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + sliderAlignment.addRule(RelativeLayout.ALIGN_PARENT_LEFT); + sliderAlignment.addRule(RelativeLayout.ALIGN_PARENT_TOP); + + artefactLayout.addView(surveyToggleSlider, sliderAlignment); + artefactLayout.addView(surveyTitle, titleAlignment); + + surveyToggleSlider.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (isChecked) { + // Set global variables + } else { + + } + } + }); + + return artefactLayout; + } + + private View videoProcessingLayout() { + final RelativeLayout videoLayout = new RelativeLayout(this); + + TextView surveyTitle = new TextView(this); + surveyTitle.setText("Video Upload"); + surveyTitle.setId(uniqueID++); + + Switch surveyToggleSlider = new Switch(this); + surveyToggleSlider.setChecked(false); + + RelativeLayout.LayoutParams sliderAlignment = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + sliderAlignment.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); + sliderAlignment.addRule(RelativeLayout.ALIGN_PARENT_TOP); + + RelativeLayout.LayoutParams titleAlignment = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + sliderAlignment.addRule(RelativeLayout.ALIGN_PARENT_LEFT); + sliderAlignment.addRule(RelativeLayout.ALIGN_PARENT_TOP); + + videoLayout.addView(surveyToggleSlider, sliderAlignment); + videoLayout.addView(surveyTitle, titleAlignment); + + surveyToggleSlider.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (isChecked) { + // Set global variables + } else { + + } + } + }); + + return videoLayout; + } + + private View audioProcessingLayout() { + final RelativeLayout audioLayout = new RelativeLayout(this); + + TextView surveyTitle = new TextView(this); + surveyTitle.setText("Audio Upload"); + surveyTitle.setId(uniqueID++); + + Switch surveyToggleSlider = new Switch(this); + surveyToggleSlider.setChecked(false); + + RelativeLayout.LayoutParams sliderAlignment = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + sliderAlignment.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); + sliderAlignment.addRule(RelativeLayout.ALIGN_PARENT_TOP); + + RelativeLayout.LayoutParams titleAlignment = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + sliderAlignment.addRule(RelativeLayout.ALIGN_PARENT_LEFT); + sliderAlignment.addRule(RelativeLayout.ALIGN_PARENT_TOP); + + audioLayout.addView(surveyToggleSlider, sliderAlignment); + audioLayout.addView(surveyTitle, titleAlignment); + + surveyToggleSlider.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (isChecked) { + // Set global variables + } else { + + } + } + }); + + return audioLayout; + } + + private View imageProcessingLayout() { + final RelativeLayout imageLayout = new RelativeLayout(this); + + TextView surveyTitle = new TextView(this); + surveyTitle.setText("Image Upload"); + surveyTitle.setId(uniqueID++); + + Switch surveyToggleSlider = new Switch(this); + surveyToggleSlider.setChecked(false); + + RelativeLayout.LayoutParams sliderAlignment = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + sliderAlignment.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); + sliderAlignment.addRule(RelativeLayout.ALIGN_PARENT_TOP); + + RelativeLayout.LayoutParams titleAlignment = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + sliderAlignment.addRule(RelativeLayout.ALIGN_PARENT_LEFT); + sliderAlignment.addRule(RelativeLayout.ALIGN_PARENT_TOP); + + imageLayout.addView(surveyToggleSlider, sliderAlignment); + imageLayout.addView(surveyTitle, titleAlignment); + + surveyToggleSlider.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (isChecked) { + // Set global variables + } else { + + } + } + }); + + return imageLayout; } private View notificationLayout() { @@ -104,7 +252,7 @@ public class ExperimentSurveyCreatorActivity extends AppCompatActivity { surveyTitle.setId(uniqueID++); Switch surveyToggleSlider = new Switch(this); - surveyToggleSlider.setChecked(true); + surveyToggleSlider.setChecked(false); notificationLabels.add(surveyTitle); @@ -137,6 +285,8 @@ public class ExperimentSurveyCreatorActivity extends AppCompatActivity { } }); + notificationLayout.removeView(buttonLayout); + return notificationLayout; } @@ -386,7 +536,10 @@ public class ExperimentSurveyCreatorActivity extends AppCompatActivity { // test for git commit - if(getIntent().getIntExtra("ExperimentIndex", 0)+1 >= experimentJSON.length()){ + d("experimentLength", String.valueOf(experimentJSON.length())); + d("experimentIndex", String.valueOf(getIntent().getIntExtra("ExperimentIndex", 0))); + + if(getIntent().getIntExtra("ExperimentIndex", 0)+1 >= experimentJSON.length()){ // Check if moving out of group openPage.putExtra("ExperimentIndex", 0); if(getIntent().getIntExtra("GroupIndex", 0)+1 >= boxInfo.getJSONArray("Experiments").length()){ d("sub", "end of json check 1"); @@ -397,9 +550,15 @@ public class ExperimentSurveyCreatorActivity extends AppCompatActivity { startActivity(openPage); } } else if (getIntent().getIntExtra("GroupIndex", 0)+1 >= boxInfo.getJSONArray("Experiments").length()) { - // Should never enter this check, but edge case just incase of bug, so run function just the same - d("sub", "end of json check 2"); - allSurveyCompleted(boxInfo); + if(getIntent().getIntExtra("ExperimentIndex", 0) < experimentJSON.length()){ + d("sub", "remain in the same group"); + openPage.putExtra("ExperimentIndex", getIntent().getIntExtra("ExperimentIndex", 0) + 1); + openPage.putExtra("GroupIndex", getIntent().getIntExtra("GroupIndex", 0)); + startActivity(openPage); + } else{ + d("sub", "end of json check 2"); + allSurveyCompleted(boxInfo); + } } else { d("sub", "remain in the same group"); openPage.putExtra("ExperimentIndex", getIntent().getIntExtra("ExperimentIndex", 0) + 1); diff --git a/app/src/main/java/com/yearthreeproject/xbframework/NewBox.java b/app/src/main/java/com/yearthreeproject/xbframework/NewBox.java index 545e11f0c663158bfbf601d60e40b540e8ad7066..bd3386af73b1a029cdb42a06c545f46f914934b7 100644 --- a/app/src/main/java/com/yearthreeproject/xbframework/NewBox.java +++ b/app/src/main/java/com/yearthreeproject/xbframework/NewBox.java @@ -6,6 +6,7 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.graphics.Color; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.provider.Settings; import android.text.InputType; @@ -23,7 +24,9 @@ import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.annotation.RequiresApi; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; @@ -39,6 +42,7 @@ import org.json.JSONObject; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import static android.util.Log.d; @@ -48,28 +52,27 @@ import static android.util.Log.d; public class NewBox extends AppCompatActivity { - private Toolbar toolbar; private Uri imageUploadResultUri; - private List<EditText> groupTitlesArray = new ArrayList(); - private List<List<EditText>> experimentTitlesArray = new ArrayList(); - private List<List<EditText>> experimentDescriptionsArray = new ArrayList(); - private List<List<EditText>> experimentInstructionsArray = new ArrayList(); + private List<EditText> groupTitlesArray = new ArrayList<>(); + private List<List<EditText>> experimentTitlesArray = new ArrayList<>(); + private List<List<EditText>> experimentDescriptionsArray = new ArrayList<>(); + private List<List<EditText>> experimentInstructionsArray = new ArrayList<>(); private ImageView uploadImageButton; private int globalGroupIndex = 1; private String inFiveValue = "Select a MEECS..."; private boolean imageUploaded = false; private Toast submitToast; - // OnCreate (Main thread) + @RequiresApi(api = Build.VERSION_CODES.KITKAT) @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_new_box); - toolbar = findViewById(R.id.toolbar); + Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); - getSupportActionBar().setDisplayShowHomeEnabled(true); + Objects.requireNonNull(getSupportActionBar()).setDisplayShowHomeEnabled(true); getSupportActionBar().setLogo(R.mipmap.ic_launcher); getSupportActionBar().setDisplayUseLogoEnabled(true); @@ -142,7 +145,7 @@ public class NewBox extends AppCompatActivity { // Submit function private void submitNewBoxFunction() { - Boolean completedInfo = true; + boolean completedInfo = true; String toastText = "Need to fill out all the information to be able to submit box for review"; // Checks for completed data @@ -251,9 +254,7 @@ public class NewBox extends AppCompatActivity { } } else { try { - if (submitToast.getView().isShown()) { - // Do nothing - } else { + if (!submitToast.getView().isShown()) { // Update when should be shown submitToast = Toast.makeText(getApplicationContext(), toastText, Toast.LENGTH_SHORT); submitToast.show(); @@ -267,6 +268,7 @@ public class NewBox extends AppCompatActivity { } // Image permission check + @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN) private void imagePermissionCheckFunction() { if (ContextCompat.checkSelfPermission(NewBox.this, Manifest.permission.READ_EXTERNAL_STORAGE) @@ -457,21 +459,21 @@ public class NewBox extends AppCompatActivity { experimentTitleEditText.setHint("Title"); experimentTitleEditText.setInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME); - experimentTitlesArray.add(new ArrayList()); + experimentTitlesArray.add(new ArrayList<EditText>()); experimentTitlesArray.get(localGroupIndex).add(experimentTitleEditText); EditText experimentDescriptionEditText = new EditText(NewBox.this); experimentDescriptionEditText.setHint("Description"); experimentDescriptionEditText.setInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME); - experimentDescriptionsArray.add(new ArrayList()); + experimentDescriptionsArray.add(new ArrayList<EditText>()); experimentDescriptionsArray.get(localGroupIndex).add(experimentDescriptionEditText); EditText experimentInstructionsEditText = new EditText(NewBox.this); experimentInstructionsEditText.setHint("Instructions"); experimentInstructionsEditText.setInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME); - experimentInstructionsArray.add(new ArrayList()); + experimentInstructionsArray.add(new ArrayList<EditText>()); experimentInstructionsArray.get(localGroupIndex).add(experimentInstructionsEditText); experimentSettingsEditTextLayout.addView(experimentTitleEditText); @@ -533,29 +535,25 @@ public class NewBox extends AppCompatActivity { // Permission processing @Override public void onRequestPermissionsResult(int requestCode, - String[] permissions, int[] grantResults) { - switch (requestCode) { - case 1: { - // If request is cancelled, the result arrays are empty. - if (grantResults.length > 0 - && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - d("Perm", "granted"); - startImageUpload(); - } else { - AlertDialog.Builder builder = new AlertDialog.Builder(NewBox.this); - builder.setTitle("Permission Required") - .setMessage("Permission to device storage is required for image upload.") - .setPositiveButton("Ok", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - Intent intent = new Intent(); - intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); - intent.setData(Uri.fromParts("package", getPackageName(), null)); - startActivityForResult(intent, 5); - } - }).setNegativeButton("Cancel", null).show(); - } - return; + @NonNull String[] permissions, @NonNull int[] grantResults) { + if (requestCode == 1) {// If request is cancelled, the result arrays are empty. + if (grantResults.length > 0 + && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + d("Perm", "granted"); + startImageUpload(); + } else { + AlertDialog.Builder builder = new AlertDialog.Builder(NewBox.this); + builder.setTitle("Permission Required") + .setMessage("Permission to device storage is required for image upload.") + .setPositiveButton("Ok", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Intent intent = new Intent(); + intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); + intent.setData(Uri.fromParts("package", getPackageName(), null)); + startActivityForResult(intent, 5); + } + }).setNegativeButton("Cancel", null).show(); } } }