Commit 1974bd94 authored by Anuththara18's avatar Anuththara18

Alternating Attention - Removing Buttons

parent 7890ab2b
...@@ -44,7 +44,7 @@ public class AlternatingAttentionGame1 extends AppCompatActivity { ...@@ -44,7 +44,7 @@ public class AlternatingAttentionGame1 extends AppCompatActivity {
SQLiteDatabase mDatabase; SQLiteDatabase mDatabase;
ImageView imageView1, imageView2, cross_btn; ImageView imageView1, imageView2, cross_btn;
ImageButton red_btn_left, red_btn_right; //ImageButton red_btn_left, red_btn_right;
TextView textView; TextView textView;
Random random = new Random(); Random random = new Random();
...@@ -100,8 +100,8 @@ public class AlternatingAttentionGame1 extends AppCompatActivity { ...@@ -100,8 +100,8 @@ public class AlternatingAttentionGame1 extends AppCompatActivity {
imageView1 = findViewById(R.id.imageView1); imageView1 = findViewById(R.id.imageView1);
imageView2 = findViewById(R.id.imageView2); imageView2 = findViewById(R.id.imageView2);
red_btn_left = findViewById(R.id.red_btn_left); //red_btn_left = findViewById(R.id.red_btn_left);
red_btn_right = findViewById(R.id.red_btn_right); //red_btn_right = findViewById(R.id.red_btn_right);
textView = findViewById(R.id.textView); textView = findViewById(R.id.textView);
cross_btn = (ImageView) findViewById(R.id.cross_btn); cross_btn = (ImageView) findViewById(R.id.cross_btn);
...@@ -148,14 +148,15 @@ public class AlternatingAttentionGame1 extends AppCompatActivity { ...@@ -148,14 +148,15 @@ public class AlternatingAttentionGame1 extends AppCompatActivity {
if( side.equals("left")) { if( side.equals("left")) {
radomImage = random.nextInt(4); radomImage = random.nextInt(4);
imageView2.setVisibility(View.INVISIBLE); //imageView2.setVisibility(View.INVISIBLE);
imageView2.setImageResource(0);
imageView1.setVisibility(View.VISIBLE); imageView1.setVisibility(View.VISIBLE);
if (leftcount > 3 ){ if (leftcount > 3 ){
leftcount = 0; leftcount = 0;
} }
imageView1.setImageResource(left_images[leftcount]); imageView1.setImageResource(left_images[leftcount]);
red_btn_left.setEnabled(true); imageView1.setEnabled(true);
red_btn_right.setEnabled(true); imageView2.setEnabled(true);
leftcount++; leftcount++;
startTime = System.currentTimeMillis(); startTime = System.currentTimeMillis();
clickedSide = "left"; clickedSide = "left";
...@@ -168,14 +169,15 @@ public class AlternatingAttentionGame1 extends AppCompatActivity { ...@@ -168,14 +169,15 @@ public class AlternatingAttentionGame1 extends AppCompatActivity {
// appearance - 1s * 20 times // appearance - 1s * 20 times
else { else {
radomImage = random.nextInt(4); radomImage = random.nextInt(4);
imageView1.setVisibility(View.INVISIBLE); //imageView1.setVisibility(View.INVISIBLE);
imageView1.setImageResource(0);
imageView2.setVisibility(View.VISIBLE); imageView2.setVisibility(View.VISIBLE);
if (rightcount > 3 ){ if (rightcount > 3 ){
rightcount = 0; rightcount = 0;
} }
imageView2.setImageResource(right_images[rightcount]); imageView2.setImageResource(right_images[rightcount]);
red_btn_left.setEnabled(true); imageView1.setEnabled(true);
red_btn_right.setEnabled(true); imageView2.setEnabled(true);
rightcount++; rightcount++;
startTime = System.currentTimeMillis(); startTime = System.currentTimeMillis();
clickedSide = "right"; clickedSide = "right";
...@@ -217,78 +219,48 @@ public class AlternatingAttentionGame1 extends AppCompatActivity { ...@@ -217,78 +219,48 @@ public class AlternatingAttentionGame1 extends AppCompatActivity {
} }
}.run(); }.run();
red_btn_left.setOnTouchListener(new View.OnTouchListener() { imageView1.setOnClickListener(new View.OnClickListener() {
@Override @Override
public boolean onTouch(View view, MotionEvent motionEvent) { public void onClick(View view) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN: {
red_btn_left.getBackground().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
view.invalidate();
mp2 = MediaPlayer.create(getApplicationContext(), R.raw.button_click); mp2 = MediaPlayer.create(getApplicationContext(), R.raw.button_click);
mp2.start(); mp2.start();
break;
}
case MotionEvent.ACTION_UP:
// Your action here on button click
clickedTime = System.currentTimeMillis(); clickedTime = System.currentTimeMillis();
reactionTime = ( clickedTime - startTime ); reactionTime = ( clickedTime - startTime );
if (clickedSide.equals("left")) { if (clickedSide.equals("left")) {
totalReactionTime = totalReactionTime + reactionTime; totalReactionTime = totalReactionTime + reactionTime;
Log.d("correct " , startTime + " " + clickedTime + " " + reactionTime); Log.d("correct " , startTime + " " + clickedTime + " " + reactionTime);
noOfCorrectResponses++; noOfCorrectResponses++;
red_btn_left.setEnabled(false); imageView1.setEnabled(false);
} }
else { else {
Log.d( "wrong" , startTime + " " + clickedTime + " " + reactionTime); Log.d( "wrong" , startTime + " " + clickedTime + " " + reactionTime);
noOfCommissionErrors++; noOfCommissionErrors++;
} }
case MotionEvent.ACTION_CANCEL: {
red_btn_left.getBackground().clearColorFilter();
view.invalidate();
break;
}
}
return true;
} }
}); });
red_btn_right.setOnTouchListener(new View.OnTouchListener() { imageView2.setOnClickListener(new View.OnClickListener() {
@Override @Override
public boolean onTouch(View view, MotionEvent motionEvent) { public void onClick(View view) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN: {
red_btn_right.getBackground().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
view.invalidate();
mp3 = MediaPlayer.create(getApplicationContext(), R.raw.button_click); mp3 = MediaPlayer.create(getApplicationContext(), R.raw.button_click);
mp3.start(); mp3.start();
break;
}
case MotionEvent.ACTION_UP:
// Your action here on button click
clickedTime = System.currentTimeMillis(); clickedTime = System.currentTimeMillis();
reactionTime = ( clickedTime - startTime ); reactionTime = ( clickedTime - startTime );
if (clickedSide.equals("right")) { if (clickedSide.equals("right")) {
totalReactionTime = totalReactionTime + reactionTime; totalReactionTime = totalReactionTime + reactionTime;
Log.d("correct " , startTime + " " + clickedTime + " " + reactionTime); Log.d("correct " , startTime + " " + clickedTime + " " + reactionTime);
noOfCorrectResponses++; noOfCorrectResponses++;
red_btn_right.setEnabled(false); imageView2.setEnabled(false);
} }
else { else {
Log.d( "wrong" , startTime + " " + clickedTime + " " + reactionTime); Log.d( "wrong" , startTime + " " + clickedTime + " " + reactionTime);
noOfCommissionErrors++; noOfCommissionErrors++;
} }
case MotionEvent.ACTION_CANCEL: {
red_btn_right.getBackground().clearColorFilter();
view.invalidate();
break;
}
}
return true;
} }
}); });
cross_btn.setOnTouchListener(new View.OnTouchListener() { cross_btn.setOnTouchListener(new View.OnTouchListener() {
@Override @Override
public boolean onTouch(View view, MotionEvent motionEvent) { public boolean onTouch(View view, MotionEvent motionEvent) {
......
...@@ -73,6 +73,7 @@ ...@@ -73,6 +73,7 @@
app:layout_constraintStart_toEndOf="@+id/imageView6" app:layout_constraintStart_toEndOf="@+id/imageView6"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<!--
<ImageButton <ImageButton
android:id="@+id/red_btn_right" android:id="@+id/red_btn_right"
android:layout_width="150dp" android:layout_width="150dp"
...@@ -95,4 +96,6 @@ ...@@ -95,4 +96,6 @@
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" /> app:layout_constraintStart_toStartOf="parent" />
-->
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment