Skip to content
Snippets Groups Projects
Commit 75bbc3ce authored by ect1u17's avatar ect1u17
Browse files

Metronome and timer added roughly into the application.

parent 8f2861d5
No related branches found
No related tags found
No related merge requests found
Showing
with 733 additions and 43 deletions
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JetCodeStyleSettings>
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
<value>
<package name="java.util" alias="false" withSubpackages="false" />
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
<package name="io.ktor" alias="false" withSubpackages="true" />
</value>
</option>
<option name="PACKAGES_IMPORT_LAYOUT">
<value>
<package name="" alias="false" withSubpackages="true" />
<package name="java" alias="false" withSubpackages="true" />
<package name="javax" alias="false" withSubpackages="true" />
<package name="kotlin" alias="false" withSubpackages="true" />
<package name="" alias="true" withSubpackages="true" />
</value>
</option>
</JetCodeStyleSettings>
<codeStyleSettings language="XML">
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
......
......@@ -78,6 +78,13 @@
android:theme="@style/AppTheme.NoActionBar"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".GroupsActivity"
android:screenOrientation="portrait"
android:label="Groups"
android:theme="@style/AppTheme.NoActionBar"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".SurveyResponseActivity"
android:screenOrientation="portrait"
......@@ -85,6 +92,27 @@
android:theme="@style/AppTheme.NoActionBar"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".SettingsActivity"
android:screenOrientation="portrait"
android:label="User Settings"
android:theme="@style/AppTheme.NoActionBar"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".MetronomeActivity"
android:screenOrientation="portrait"
android:label="Metronome test"
android:theme="@style/AppTheme.NoActionBar"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".SecondActivityMetronome"
android:screenOrientation="portrait"
android:label="Metronome test 2"
android:theme="@style/AppTheme.NoActionBar"
tools:ignore="LockedOrientationActivity" />
<activity android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
android:screenOrientation="portrait"
android:theme="@style/Base.Theme.AppCompat"
......
package com.yearthreeproject.xbframework;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.os.Build;
......@@ -42,6 +43,7 @@ public class ExperimentActivity extends AppCompatActivity {
private App realmApp;
private ArrayList<RadioButton> experimentsRadioButtonArray;
private ArrayList<Integer> idsSeen = new ArrayList<>();
@Override
public boolean onSupportNavigateUp() {
......@@ -63,7 +65,6 @@ public class ExperimentActivity extends AppCompatActivity {
}
setSupportActionBar(toolbar);
requireNonNull(getSupportActionBar()).setDisplayShowHomeEnabled(true);
getSupportActionBar().setLogo(R.mipmap.ic_launcher);
getSupportActionBar().setDisplayUseLogoEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
......@@ -73,6 +74,16 @@ public class ExperimentActivity extends AppCompatActivity {
try {
JSONObject boxJSON = new JSONObject(requireNonNull(getIntent().getStringExtra("JSON")));
if("Sleep".equals(boxJSON.optString("category"))){
getSupportActionBar().setLogo(R.mipmap.sleep_logo);
} else if ("Eat".equals(boxJSON.optString("category"))){
getSupportActionBar().setLogo(R.mipmap.eat_logo);
} else if("Engage".equals(boxJSON.optString("category"))){
getSupportActionBar().setLogo(R.mipmap.engage_logo);
} else {
getSupportActionBar().setLogo(R.mipmap.ic_launcher);
}
setTitle(boxJSON.optString("name"));
TextView boxDescription = new TextView(this);
......@@ -125,6 +136,14 @@ public class ExperimentActivity extends AppCompatActivity {
experimentsRadioButtonArray.get(x).setChecked(false);
else experimentsRadioButtonArray.get(x).setChecked(true);
}
if(!idsSeen.contains(v.getId())){
idsSeen.add(v.getId());
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle(experiment.optString("name"));
alert.setMessage("Instructions: " + experiment.optString("instructions") + "\n\nDescription: " + experiment.optString("description"));
alert.setPositiveButton("OK", null);
alert.show();
}
});
experimentsRadioButtonArray.add(experimentRadioButton);
......
......@@ -26,7 +26,6 @@ import org.bson.Document;
import org.json.JSONException;
import org.json.JSONObject;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
......@@ -89,7 +88,7 @@ public class MainActivity extends AppCompatActivity {
savedSettingsEditor.apply();
recreate();
} else if (!realmApp.currentUser().isLoggedIn()){
d("test", "realmapp not logged in");
d("test", "realmApp not logged in");
SharedPreferences.Editor savedSettingsEditor = savedSettings.edit();
savedSettingsEditor.putBoolean("loggedIn", false);
savedSettingsEditor.apply();
......@@ -135,11 +134,11 @@ public class MainActivity extends AppCompatActivity {
ProjectMacros.saveFile(MainActivity.this, "localUserData.json", user.toString());
/*
// DEBUG INTENT FOR QUICK ACCESS TO ANOTHER INTENT
Intent open_quicker_DEBUG = new Intent(this, ProgressActivity.class);
Intent open_quicker_DEBUG = new Intent(this, MetronomeActivity.class);
startActivity(open_quicker_DEBUG);
*/
if(user.optJSONObject("current_experiment").optBoolean("locked", false)) checkReleaseFromExperiment();
else checkNotifications();
......@@ -175,7 +174,7 @@ public class MainActivity extends AppCompatActivity {
experimentsButton.setOnClickListener(v -> launchBoxPage());
surveyButton.setOnClickListener(this::surveyButtonEvent);
} catch (JSONException | ParseException e) {
} catch (JSONException e) {
e.printStackTrace();
}
} else {
......@@ -205,7 +204,8 @@ public class MainActivity extends AppCompatActivity {
if (user.optJSONObject("current_experiment") != null &&
user.optJSONObject("current_experiment").optBoolean("locked")) {
alert.setTitle(user.optJSONObject("current_experiment").optJSONArray("experiment").optJSONObject(0).optString("name"));
alert.setMessage(user.optJSONObject("current_experiment").optJSONArray("experiment").optJSONObject(0).optString("instructions"));
alert.setMessage("Instructions: " + user.optJSONObject("current_experiment").optJSONArray("experiment").optJSONObject(0).optString("instructions")
+ "\n\nDescription: " + user.optJSONObject("current_experiment").optJSONArray("experiment").optJSONObject(0).optString("description"));
} else {
alert.setTitle("Pick an experiment!");
alert.setMessage("You are not signed up for an experiment yet, head to 'Boxes' to pick one!");
......@@ -218,6 +218,9 @@ public class MainActivity extends AppCompatActivity {
alert.setMessage("You only have " + item.getTitle() + " on the current experiment, then you may pick another one!");
alert.setPositiveButton("OK", null);
alert.show();
} else if (id == R.id.menu_main_settings){
// launch intent for settings
startActivityToRecreateOnExit(SettingsActivity.class);
}
return super.onOptionsItemSelected(item);
}
......@@ -251,20 +254,22 @@ public class MainActivity extends AppCompatActivity {
}
@RequiresApi(api = Build.VERSION_CODES.N)
private void checkReleaseFromExperiment() throws JSONException, ParseException {
private void checkReleaseFromExperiment() throws JSONException {
JSONObject currentExperimentJson = user.optJSONObject("current_experiment");
Date today = new Date();
Date endDate = new Date();
if(currentExperimentJson.optString("date_until") != "null"){
if(!currentExperimentJson.optString("date_until").equals("null")){
endDate.setTime(Long.parseLong(currentExperimentJson.optJSONObject("date_until").optString("$date")));
}
if(today.compareTo(endDate) >= 0){
if(currentExperimentJson.optJSONArray("experiment").optJSONObject(0).optJSONArray("notification") != null) {
for (int i = 0; i < currentExperimentJson.optJSONArray("experiment").optJSONObject(0).getJSONArray("notification").length(); i++) {
JSONObject notificationObject = currentExperimentJson.optJSONArray("experiment").optJSONObject(0).optJSONArray("notification").optJSONObject(i);
ProjectMacros.cancelNotification(notificationObject.optString("name"), notificationObject.optString("message"), MainActivity.this);
}
}
currentExperimentJson.put("locked", false);
currentExperimentJson.put("id", JSONObject.NULL);
......
package com.yearthreeproject.xbframework;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.view.View;
import android.widget.SeekBar;
public class Metronome extends View {
private int defaultBPM;
private int minBPM;
private int maxBPM;
private Runnable textChangingRunnable;
private Runnable beatRunnable;
private float msPerCycle;
private float mBpm;
private long lastTick;
private float position;
public Metronome(Context context, AttributeSet attrs){
super(context, attrs);
lastTick = SystemClock.elapsedRealtime();
readAttrs(attrs);
checks();
setBPM(defaultBPM);
}
private void readAttrs(AttributeSet attrs) {
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Metronome);
defaultBPM = a.getInt(R.styleable.Metronome_defaultBpm, defaultBPM);
minBPM = a.getInt(R.styleable.Metronome_minBpm, minBPM);
maxBPM = a.getInt(R.styleable.Metronome_maxBpm, maxBPM);
a.recycle();
}
private void checks() {
if (defaultBPM == 0 || minBPM == 0 || maxBPM == 0) {
throw new RuntimeException("Need defaultBpm, minBpm and max Bpm");
}
if (!(minBPM < defaultBPM && defaultBPM < maxBPM)) {
throw new RuntimeException("minBpm < defaultBpm < maxBpm does not hold, but it must");
}
}
public void setBPM(float bpm) {
if (bpm < minBPM) {
bpm = minBPM;
} else if (bpm > maxBPM) {
bpm = maxBPM;
}
final float beatsPerSeconds = bpm / 60;
final float millisecondsPerBeat = 1000 / beatsPerSeconds;
msPerCycle = millisecondsPerBeat * 2;
System.out.println("should be before1 " + mBpm);
mBpm = bpm;
System.out.println("should be after1 " + mBpm);
if (textChangingRunnable != null) {
textChangingRunnable.run();
}
}
public void setBeatRunnable(Runnable beatRunnable) {
this.beatRunnable = beatRunnable;
}
public float getBpm() {
return mBpm;
}
public int getDefaultBpm() {
return defaultBPM;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
updateRunnableBeat();
invalidate();
}
private void updateRunnableBeat() {
long elapsedTime = progressTime();
final float progression = elapsedTime / msPerCycle;
boolean makeBeat = false;
if (position < 0.5 && position + progression >= 0.5) {
makeBeat = true;
} else if (position < 1.0 && position + progression >= 1.0) {
makeBeat = true;
}
if (makeBeat && beatRunnable != null) {
beatRunnable.run();
}
position += progression;
while (position > 1.0) {
position -= 1.0;
}
}
private long progressTime() {
long newTime = SystemClock.elapsedRealtime();
long elapsedTime = newTime - lastTick;
lastTick = newTime;
return elapsedTime > 0 ? elapsedTime : 0;
}
public void setBar(SeekBar bar){
final int step = 1;
int max = 200;
final int min = 20;
bar.setMax( (max - min) / step );
bar.setProgress((int) getBpm());
bar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
double value = min + (progress * step);
setBPM((float) value);
}
});
}
public void setBpmChangedRunnable(Runnable bpmChangedRunnable) {
textChangingRunnable = bpmChangedRunnable;
}
}
\ No newline at end of file
package com.yearthreeproject.xbframework;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class MetronomeActivity extends AppCompatActivity {
private TextView timerValue;
private Button startButton;
private Button pauseButton;
private Button stopButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_metronome);
timerValue = (TextView) findViewById(R.id.timerValue);
startButton = (Button) findViewById(R.id.startButton);
pauseButton = (Button) findViewById(R.id.pauseButton);
stopButton = (Button) findViewById(R.id.stopButton);
Timer timer = new Timer(startButton, pauseButton, stopButton, timerValue);
Button toolThree = (Button) findViewById(R.id.button2);
toolThree.setOnClickListener(view -> startActivity(new Intent(MetronomeActivity.this, SecondActivityMetronome.class)));
}
}
......@@ -162,32 +162,27 @@ public class ProgressActivity extends AppCompatActivity {
resultsData = progressJson.getJSONArray("results");
journalArray = progressJson.getJSONArray("journal").getJSONObject(0).getJSONArray("entries");
d(TAG, "initialiseGlobalVariables: " + completionsData);
graphSelectedDate = new Date();
journalSelectedDate = new Date();
completionsExist = completionsData != null;
resultsExist = resultsData != null;
d(TAG, "initialiseGlobalVariables: " + completionsExist);
completionsExist = completionsData != null && completionsData.length() > 1;
resultsExist = resultsData != null && resultsData.length() > 1;
List<DataPoint> dataSeries = null;
// Need set up completions to be shown in the graphs
if(resultsExist){ // If there is only archive this will be the latest ran
d(TAG, "initialiseGlobalVariables: " + resultsData.getJSONArray(resultsData.length()-1));
latestResultsExperimentId = resultsData.getJSONArray(resultsData.length()-1).getJSONObject(0).getString("experiment");
latestResultsEndDate = resultsData.getJSONArray(resultsData.length()-1).getJSONObject(0).getJSONObject("end_date").getString("$date");
latestExperimentDate = resultsData.getJSONArray(resultsData.length()-1).getJSONObject(0).getJSONObject("date").getString("$date");
dataSeries = arrayLoopForSelectedDateForData(resultsData, new ArrayList<>(), latestResultsExperimentId, latestExperimentDate);
}
if(completionsExist){ // If there is also currentExperiment this will run latest, making this the highest selected graph
/*latestResultsExperimentId = localUserJson.getJSONObject("current_experiment").getJSONArray("experiment").getJSONObject(0).getString("name");
latestResultsExperimentId = localUserJson.getJSONObject("current_experiment").getJSONArray("experiment").getJSONObject(0).getString("name");
latestResultsEndDate = completionsData.getJSONArray(completionsData.length()-1).getJSONObject(0).getJSONObject("end_date").getString("$date");
latestExperimentDate = completionsData.getJSONArray(completionsData.length()-1).getJSONObject(0).getJSONObject("date").getString("$date");
dataSeries = arrayLoopForSelectedDateForData(completionsData, new ArrayList<>(), latestResultsExperimentId, latestResultsEndDate);*/
dataSeries = arrayLoopForSelectedDateForData(completionsData, new ArrayList<>(), latestResultsExperimentId, latestResultsEndDate);
}
initialiseGraphGUI(dataSeries);
}
......@@ -232,7 +227,7 @@ public class ProgressActivity extends AppCompatActivity {
}
@RequiresApi(api = Build.VERSION_CODES.M)
private void initialiseGraphGUI(List<DataPoint> dataSeries) throws JSONException, ParseException {
private void initialiseGraphGUI(List<DataPoint> dataSeries) throws JSONException {
generateGraphCalendar();
if(completionsExist){
......@@ -718,7 +713,7 @@ public class ProgressActivity extends AppCompatActivity {
if(completionsExist){
for(int i = 0; i < completionsData.length(); i++){
queryDate.setTime(Long.parseLong(completionsData.getJSONArray(i).getJSONObject(0).getJSONObject("date").getString("$date")));;
queryDate.setTime(Long.parseLong(completionsData.getJSONArray(i).getJSONObject(0).getJSONObject("date").getString("$date")));
if(DateUtils.isToday(Long.parseLong(completionsData.getJSONArray(i).getJSONObject(0).getJSONObject("date").getString("$date")))){
graphCalendarView.setCurrentDayBackgroundColor(Color.parseColor(markColor[markColorIndex%3]));
}
......@@ -769,7 +764,7 @@ public class ProgressActivity extends AppCompatActivity {
String graphTitleString = "Experiment: " + experimentName;
graphSelectedTextView.setText(graphTitleString);
}
} catch (JSONException | ParseException e){
} catch (JSONException e){
e.printStackTrace();
}
}
......@@ -910,6 +905,7 @@ public class ProgressActivity extends AppCompatActivity {
dataSeries = loopJSONArrayForPoints(completionsData, new ArrayList<>());
lowest = loopJSONArrayForLowest(completionsData, lowest);
} else {
d(TAG, "generateOverallGraph: new stuff" );
//dataSeries = loopJSONArrayForPoints(resultsData, new ArrayList<>());
//lowest = loopJSONArrayForLowest(resultsData, lowest);
}
......@@ -997,7 +993,7 @@ public class ProgressActivity extends AppCompatActivity {
}
private List<DataPoint> arrayLoopForSelectedDateForData(JSONArray array, List<DataPoint> dataSeries, String experimentName, String experimentStartDate) throws JSONException, ParseException {
private List<DataPoint> arrayLoopForSelectedDateForData(JSONArray array, List<DataPoint> dataSeries, String experimentName, String experimentStartDate) throws JSONException {
Date queryEntryDate = new Date();
for (int i = 0; i < array.length(); i++) {
JSONObject queryJSON = array.getJSONArray(i).getJSONObject(0);
......
package com.yearthreeproject.xbframework;
import android.content.SharedPreferences;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.view.WindowManager;
import android.widget.SeekBar;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class SecondActivityMetronome extends AppCompatActivity {
private final static String BPM_KEY = "bpm";
private SoundPool mSoundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
private int soundId = -1;
private Metronome mt;
private TextView bpmText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_secondt);
soundId = mSoundPool.load(this, R.raw.beat, 1);
bpmText = (TextView) findViewById(R.id.bpm_text);
mt = (Metronome) findViewById(R.id.metronomev);
mt.setBeatRunnable(new PlayBeatRunnable());
mt.setBpmChangedRunnable(new UpdateBpmTextRunnable());
SeekBar seek = (SeekBar) findViewById(R.id.seekBar);
mt.setBar(seek);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
@Override
protected void onDestroy() {
mSoundPool.release();
mSoundPool = null;
super.onDestroy();
}
@Override
protected void onPause() {
super.onPause();
storeBPM(mt);
}
private void storeBPM(Metronome source) {
SharedPreferences sp = getPreferences(MODE_PRIVATE);
SharedPreferences.Editor e = sp.edit();
e.putFloat(BPM_KEY, source.getBpm());
e.apply();
}
class UpdateBpmTextRunnable implements Runnable {
@Override
public void run() {
int bpm = (int)(mt.getBpm() + 0.5f);
bpmText.setText(bpm + " " + getString(R.string.bpm_unit_text));
}
}
class PlayBeatRunnable implements Runnable {
@Override
public void run() {
if (mSoundPool != null && soundId != -1) {
mSoundPool.play(soundId, 1.0f /*leftVolume*/, 1.0f /*rightVolume*/, 0 /*priority*/, 0 /*loop*/, 1.0f /*rate*/);
}
}
}
}
package com.yearthreeproject.xbframework;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Iterator;
import java.util.Objects;
public class SettingsActivity extends AppCompatActivity {
private static final String TAG = "SettingsActivity";
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Objects.requireNonNull(getSupportActionBar()).setDisplayShowHomeEnabled(true);
Objects.requireNonNull(getSupportActionBar()).setLogo(R.mipmap.ic_launcher);
Objects.requireNonNull(getSupportActionBar()).setDisplayUseLogoEnabled(true);
LinearLayout settingsLayout = findViewById(R.id.settings_page);
try {
JSONObject localUserJson = new JSONObject(ProjectMacros.readFile(this, "localUserData.json"));
Iterator<String> keys = localUserJson.keys();
while(keys.hasNext()) {
String key = keys.next();
// check its not an object, and is not the user id, then create the layout to show the item
if (!(localUserJson.get(key) instanceof JSONObject || localUserJson.get(key) instanceof JSONArray || key.equals("_user_id"))) {
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.HORIZONTAL);
TextView title = new TextView(this);
String keyFormatted = key.substring(0, 1).toUpperCase() + key.substring(1);
title.setText(keyFormatted + ": ");
title.setTypeface(null, Typeface.BOLD);
title.setTextSize(22);
TextView settingValue = new TextView(this);
settingValue.setText(localUserJson.getString(key));
settingValue.setTextSize(22);
layout.addView(title);
layout.addView(settingValue);
settingsLayout.addView(layout);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
......@@ -88,7 +88,6 @@ public class SurveyResponseActivity extends AppCompatActivity {
}
setSupportActionBar(toolbar);
Objects.requireNonNull(getSupportActionBar()).setDisplayShowHomeEnabled(true);
getSupportActionBar().setLogo(R.mipmap.ic_launcher);
getSupportActionBar().setDisplayUseLogoEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
......@@ -118,6 +117,17 @@ public class SurveyResponseActivity extends AppCompatActivity {
JSONObject localUserJson = new JSONObject(ProjectMacros.readFile(this, "localUserData.json"));
if("Sleep".equals(localUserJson.getJSONObject("current_experiment").getJSONArray("experiment").getJSONObject(0).optString("category"))){
getSupportActionBar().setLogo(R.mipmap.sleep_logo);
} else if ("Eat".equals(localUserJson.getJSONObject("current_experiment").getJSONArray("experiment").getJSONObject(0).optString("category"))){
getSupportActionBar().setLogo(R.mipmap.eat_logo);
} else if("Engage".equals(localUserJson.getJSONObject("current_experiment").getJSONArray("experiment").getJSONObject(0).optString("category"))){
getSupportActionBar().setLogo(R.mipmap.engage_logo);
} else {
// this is always going to be default since there is no check to see what the result actuall is...
getSupportActionBar().setLogo(R.mipmap.ic_launcher);
}
JSONArray completionQuestions = localUserJson.getJSONObject("current_experiment").getJSONArray("experiment").getJSONObject(0).optJSONArray("completion_questions");
......@@ -146,12 +156,13 @@ public class SurveyResponseActivity extends AppCompatActivity {
if(surveyQuestions != null){
TextView surveyTagTitle = new TextView(this);
surveyTagTitle.setText("Scientific Survey");
surveyTagTitle.setTextSize(Float.parseFloat("30"));
surveyTagTitle.setTextSize(Float.parseFloat("26"));
surveyScrollView.addView(surveyTagTitle);
for (int i = 0; i < surveyQuestions.length(); i++) {
surveyResponses.add(new JSONObject()
.put("type", surveyQuestions.getJSONObject(i).getString("type"))
.put("agree", surveyQuestions.getJSONObject(i).optString("agree", "good"))
.put("response", JSONObject.NULL)
.put("question", surveyQuestions.getJSONObject(i).getString("question")));
......@@ -186,13 +197,18 @@ public class SurveyResponseActivity extends AppCompatActivity {
String[] values = completionResponses.get(i).optString("expected").split("-");
int lowerValue = Integer.parseInt(values[0]);
int upperValue = Integer.parseInt(values[1]);
int queryInt = Integer.parseInt(completionResponses.get(i).optString("response"));
if(values[1] != null) {
int upperValue = Integer.parseInt(values[1]);
if (queryInt <= upperValue &&
lowerValue <= queryInt) {
d("test", "int completed correctly");
completedResults++;
}
} else if(queryInt == lowerValue) {
d("test", "int completed correctly");
completedResults++;
}
}
break;
case "date":
......@@ -242,11 +258,19 @@ public class SurveyResponseActivity extends AppCompatActivity {
double completionPercent = (completedResults / (double) totalPossibleResults)*100;
d("test", String.valueOf(completionPercent));
int perceptionResponseTotal = 0;
for (int i = 0; i < surveyResponses.size(); i++) {
if (surveyResponses.get(i).optString("response").equals("null")) correctSubmission = false;
rawSurveyResults.add(Document.parse(surveyResponses.get(i).toString()));
if("bad".equals(surveyResponses.get(i).optString("agree"))){
perceptionResponseTotal += (5-surveyResponses.get(i).optInt("response"));
} else {
perceptionResponseTotal += surveyResponses.get(i).optInt("response");
}
}
double responseAverage = (perceptionResponseTotal / (double) (surveyResponses.size()+1))*100;
d(TAG, "completeSubmission: " + responseAverage);
for(int i = 0; i < perceptionResponses.size(); i++){
if(perceptionResponses.get(i).optString("response").equals("null")) correctSubmission = false;
......@@ -625,18 +649,24 @@ public class SurveyResponseActivity extends AppCompatActivity {
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int width = displayMetrics.widthPixels;
for (int i = 0; i < 3; i++) {
for (int i = 0; i < 5; i++) {
textViewArray.add(new TextView(this));
switch(i + 1){
case 1:
textViewArray.get(i).setText("Worse");
textViewArray.get(i).setText("Much Worse");
break;
case 2:
textViewArray.get(i).setText("The same");
textViewArray.get(i).setText("Worse");
break;
case 3:
textViewArray.get(i).setText("The same");
break;
case 4:
textViewArray.get(i).setText("Better");
break;
case 5:
textViewArray.get(i).setText("Much Better");
break;
default:
textViewArray.get(i).setText("Error");
}
......@@ -644,7 +674,7 @@ public class SurveyResponseActivity extends AppCompatActivity {
textViewArray.get(i).setGravity(Gravity.CENTER);
textViewArray.get(i).setId(uniqueId++);
textViewArrayAlignment.add(new RelativeLayout.LayoutParams((int) ((width * 0.9) / 3), ViewGroup.LayoutParams.WRAP_CONTENT));
textViewArrayAlignment.add(new RelativeLayout.LayoutParams((int) ((width * 0.9) / 5), ViewGroup.LayoutParams.WRAP_CONTENT));
textViewArrayAlignment.get(i).addRule(RelativeLayout.CENTER_HORIZONTAL);
......@@ -652,12 +682,12 @@ public class SurveyResponseActivity extends AppCompatActivity {
buttonArray.get(i).setId(i + 1);
buttonArray.get(i).setGravity(Gravity.CENTER);
buttonArrayAlignment.add(new RelativeLayout.LayoutParams((int) ((width * 0.9) / 3), ViewGroup.LayoutParams.WRAP_CONTENT));
buttonArrayAlignment.add(new RelativeLayout.LayoutParams((int) ((width * 0.9) / 5), ViewGroup.LayoutParams.WRAP_CONTENT));
buttonArrayAlignment.get(i).addRule(RelativeLayout.TEXT_ALIGNMENT_GRAVITY, RelativeLayout.CENTER_HORIZONTAL);
if (i != 0)
buttonArrayAlignment.get(i).addRule(RelativeLayout.RIGHT_OF, buttonArray.get(i - 1).getId());
else buttonArrayAlignment.get(i).leftMargin = (int) ((width*0.9)/(3*4));
else buttonArrayAlignment.get(i).leftMargin = (int) ((width*0.9)/(5*4));
buttonArrayAlignment.get(i).addRule(RelativeLayout.BELOW, questionText.getId());
//buttonArrayAlignment.get(i).addRule(RelativeLayout.CENTER_HORIZONTAL);
......@@ -678,14 +708,20 @@ public class SurveyResponseActivity extends AppCompatActivity {
switch(x + 1){
case 1:
response = -1;
response = -2;
break;
case 2:
response = 0;
response = -1;
break;
case 3:
response = 0;
break;
case 4:
response = 1;
break;
case 5:
response = 2;
break;
default:
response = 0;
}
......
package com.yearthreeproject.xbframework;
import android.os.Handler;
import android.os.SystemClock;
import android.widget.Button;
import android.widget.TextView;
public class Timer {
private long startTime = 0L;
private Handler customHandler = new Handler();
long timeInMilliseconds = 0L;
long timeSwapBuff = 0L;
long updatedTime = 0L;
private Button startButton;
private Button pauseButton;
private Button stopButton;
private TextView timerValue;
public Timer(Button startButton, Button pauseButton, Button stopButton, final TextView timerValue) {
this.startButton = startButton;
this.pauseButton = pauseButton;
this.stopButton = stopButton;
this.timerValue = timerValue;
startButton.setOnClickListener(view -> {
startTime = SystemClock.uptimeMillis();
customHandler.postDelayed(updateTimerThread, 0);
});
pauseButton.setOnClickListener(view -> {
timeSwapBuff += timeInMilliseconds;
customHandler.removeCallbacks(updateTimerThread);
});
stopButton.setOnClickListener(view -> {
startTime = 0L;
timeInMilliseconds = 0L;
timeSwapBuff = 0L;
updatedTime = 0L;
customHandler.removeCallbacks(updateTimerThread);
timerValue.setText("0:00:000");
});
}
private Runnable updateTimerThread = new Runnable() {
public void run() {
timeInMilliseconds = SystemClock.uptimeMillis() - startTime;
updatedTime = timeSwapBuff + timeInMilliseconds;
int secs = (int) (updatedTime / 1000);
int mins = secs / 60;
secs = secs % 60;
int milliseconds = (int) (updatedTime % 1000);
timerValue.setText("" + mins + ":"
+ String.format("%02d", secs) + ":"
+ String.format("%03d", milliseconds));
customHandler.postDelayed(this, 0);
}
};
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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=".SettingsActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:minHeight="56dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
</com.google.android.material.appbar.AppBarLayout>
<include layout="@layout/content_settings" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="#000000"
android:layout_height="match_parent" >
<TextView
android:id="@+id/timerValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/pauseButton"
android:layout_centerHorizontal="true"
android:layout_marginBottom="37dp"
android:textSize="40sp"
android:textColor="#ffffff"
android:text="@string/timerVal" />
<Button
android:id="@+id/startButton"
android:layout_width="90dp"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="38dp"
android:text="@string/startButtonLabel" />
<Button
android:id="@+id/pauseButton"
android:layout_width="90dp"
android:layout_height="45dp"
android:layout_alignBaseline="@+id/startButton"
android:layout_alignBottom="@+id/startButton"
android:layout_alignParentRight="true"
android:layout_marginRight="38dp"
android:text="@string/pauseButtonLabel" />
<Button
android:id="@+id/stopButton"
android:layout_width="90dp"
android:layout_height="45dp"
android:layout_below="@+id/timerValue"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginStart="166dp"
android:layout_marginLeft="166dp"
android:layout_marginTop="142dp"
android:layout_marginEnd="155dp"
android:layout_marginRight="155dp"
android:text="@string/stopButtonLabel" />
<Button
android:id="@+id/button2"
android:layout_width="136dp"
android:layout_height="wrap_content"
android:layout_below="@+id/stopButton"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginStart="137dp"
android:layout_marginLeft="137dp"
android:layout_marginTop="134dp"
android:layout_marginEnd="138dp"
android:layout_marginRight="138dp"
android:text="Metronome" />
</RelativeLayout>
\ No newline at end of file
<?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"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<com.yearthreeproject.xbframework.Metronome
android:id="@+id/metronomev"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:defaultBpm="76"
app:minBpm="20"
app:maxBpm="200"/>
<TextView
android:id="@+id/bpm_text"
android:layout_width="88dp"
android:layout_height="42dp"
android:layout_above="@+id/seekBar"
android:layout_alignStart="@+id/seekBar"
android:layout_alignLeft="@+id/seekBar"
android:layout_alignEnd="@+id/seekBar"
android:layout_alignRight="@+id/seekBar"
android:layout_marginStart="129dp"
android:layout_marginLeft="129dp"
android:layout_marginEnd="130dp"
android:layout_marginRight="130dp"
android:layout_marginBottom="16dp"
android:text="76 BPM"
android:textColor="#040000"
android:textSize="20sp" />
<SeekBar
android:id="@+id/seekBar"
android:layout_width="345dp"
android:layout_height="37dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="33dp"
android:layout_marginLeft="33dp"
android:layout_marginEnd="31dp"
android:layout_marginRight="31dp"
android:layout_marginBottom="534dp" />
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:id="@+id/settings_page"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
android:layout_marginTop="32dp"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".SettingsActivity"
tools:showIn="@layout/activity_settings" />
......@@ -7,8 +7,17 @@
<item
android:id="@+id/menu_main_info"
android:icon="@drawable/ic_baseline_info_24"
android:orderInCategory="100"
android:orderInCategory="99"
app:showAsAction="always"
android:title="Experiment" />
<item
android:id="@+id/menu_main_settings"
android:icon="@android:drawable/ic_menu_preferences"
android:orderInCategory="100"
android:title="Settings"
app:showAsAction="always" />
</menu>
\ No newline at end of file
File added
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="Metronome">
<attr name="defaultBpm" format="integer" />
<attr name="minBpm" format="integer" />
<attr name="maxBpm" format="integer" />
</declare-styleable>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="config_bpmTextSize">30sp</dimen>
</resources>
\ No newline at end of file
......@@ -170,4 +170,15 @@
<string name="MongoRealmId">xbframework-yvulh</string>
<string name="emailRegex" tools:ignore="TypographyDashes"><![CDATA[((?:[a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\]))]]></string>
<!-- MongoDB strings End -->
<!-- Metronome strings Start -->
<string name="bpm_unit_text">BPM</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="timerVal">0:00:000</string>
<string name="pauseButtonLabel">Pause</string>
<string name="startButtonLabel">Start</string>
<string name="stopButtonLabel">Stop</string>
<string name="two">Two</string>
<!-- Metronome strings End -->
</resources>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment