Commit 68d91859 authored by Anuththara18's avatar Anuththara18

Changing the image and the location in the focusd attention game

parent db4713fb
...@@ -140,6 +140,11 @@ ...@@ -140,6 +140,11 @@
android:name=".focused.FocusedAttentionGame1" android:name=".focused.FocusedAttentionGame1"
android:screenOrientation="landscape" android:screenOrientation="landscape"
android:theme="@style/Theme.AppCompat.NoActionBar" > android:theme="@style/Theme.AppCompat.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> </activity>
<activity <activity
android:name=".loginregistration.RegistrationActivity" android:name=".loginregistration.RegistrationActivity"
...@@ -171,11 +176,7 @@ ...@@ -171,11 +176,7 @@
android:name=".splashscreen.SplashActivity" android:name=".splashscreen.SplashActivity"
android:screenOrientation="landscape" android:screenOrientation="landscape"
android:theme="@style/Theme.AppCompat.NoActionBar"> android:theme="@style/Theme.AppCompat.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> </activity>
</application> </application>
......
package com.anuththara18.attentionassessment.focused; package com.anuththara18.attentionassessment.focused;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
...@@ -37,8 +39,14 @@ import com.anuththara18.attentionassessment.sustained.SustainedAttentionGame1; ...@@ -37,8 +39,14 @@ import com.anuththara18.attentionassessment.sustained.SustainedAttentionGame1;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.Set;
public class FocusedAttentionGame1 extends AppCompatActivity { public class FocusedAttentionGame1 extends AppCompatActivity {
...@@ -50,6 +58,7 @@ public class FocusedAttentionGame1 extends AppCompatActivity { ...@@ -50,6 +58,7 @@ public class FocusedAttentionGame1 extends AppCompatActivity {
Random random = new Random(); Random random = new Random();
int radomTimer = 0; int radomTimer = 0;
int rand = 0;
int i = 1; int i = 1;
private long startTime, clickedTime = 0; private long startTime, clickedTime = 0;
...@@ -63,7 +72,7 @@ public class FocusedAttentionGame1 extends AppCompatActivity { ...@@ -63,7 +72,7 @@ public class FocusedAttentionGame1 extends AppCompatActivity {
int meanReactionTime = 0; int meanReactionTime = 0;
int duration = 0; int duration = 0;
ImageView imageView, cross_btn; ImageView imageView, cross_btn, imageView2, imageView3, imageView4, imageView5, imageView6;
ImageButton red_btn; ImageButton red_btn;
TextView textView; TextView textView;
...@@ -71,6 +80,9 @@ public class FocusedAttentionGame1 extends AppCompatActivity { ...@@ -71,6 +80,9 @@ public class FocusedAttentionGame1 extends AppCompatActivity {
Integer[] isi = { 3000, 3500, 4000, 4500, 5000, 5500, 6000 }; Integer[] isi = { 3000, 3500, 4000, 4500, 5000, 5500, 6000 };
Integer[] images = {R.drawable.monkey, R.drawable.baby_zebra, R.drawable.elephant, R.drawable.pig, R.drawable.giraffe,
R.drawable.cow, R.drawable.horse, R.drawable.dino, R.drawable.lion, R.drawable.dog};
MediaPlayer mp, mp2; MediaPlayer mp, mp2;
@Override @Override
...@@ -86,11 +98,16 @@ public class FocusedAttentionGame1 extends AppCompatActivity { ...@@ -86,11 +98,16 @@ public class FocusedAttentionGame1 extends AppCompatActivity {
setContentView(R.layout.activity_focused_attention_game1); setContentView(R.layout.activity_focused_attention_game1);
imageView = (ImageView) findViewById(R.id.imageView); imageView = (ImageView) findViewById(R.id.imageView);
imageView2 = (ImageView) findViewById(R.id.imageView2);
imageView3 = (ImageView) findViewById(R.id.imageView3);
imageView4 = (ImageView) findViewById(R.id.imageView4);
imageView5 = (ImageView) findViewById(R.id.imageView5);
imageView6 = (ImageView) findViewById(R.id.imageView6);
cross_btn = (ImageView) findViewById(R.id.cross_btn); cross_btn = (ImageView) findViewById(R.id.cross_btn);
red_btn = (ImageButton) findViewById(R.id.red_btn); red_btn = (ImageButton) findViewById(R.id.red_btn);
textView = (TextView) findViewById(R.id.textView); textView = (TextView) findViewById(R.id.textView);
textView.setText(LanguageSetter.getresources().getString(R.string.focg1)); //textView.setText(LanguageSetter.getresources().getString(R.string.focg1));
mp = MediaPlayer.create(getApplicationContext(), R.raw.focused); mp = MediaPlayer.create(getApplicationContext(), R.raw.focused);
mp.start(); mp.start();
...@@ -100,6 +117,18 @@ public class FocusedAttentionGame1 extends AppCompatActivity { ...@@ -100,6 +117,18 @@ public class FocusedAttentionGame1 extends AppCompatActivity {
//creating a database //creating a database
mDatabase = openOrCreateDatabase(DATABASE_NAME, MODE_PRIVATE, null); mDatabase = openOrCreateDatabase(DATABASE_NAME, MODE_PRIVATE, null);
List<Integer> unpickedNumbers = new ArrayList<Integer>();
unpickedNumbers.add(0);
unpickedNumbers.add(1);
unpickedNumbers.add(2);
unpickedNumbers.add(3);
unpickedNumbers.add(4);
unpickedNumbers.add(5);
unpickedNumbers.add(6);
unpickedNumbers.add(7);
unpickedNumbers.add(8);
unpickedNumbers.add(9);
new Runnable() { new Runnable() {
int updateInterval; int updateInterval;
...@@ -109,8 +138,12 @@ public class FocusedAttentionGame1 extends AppCompatActivity { ...@@ -109,8 +138,12 @@ public class FocusedAttentionGame1 extends AppCompatActivity {
if ( i <= 41 ) { // 41 times if ( i <= 41 ) { // 41 times
if ( i % 2 != 0 ) { if ( i % 2 != 0 ) {
imageView.setVisibility(View.INVISIBLE); imageView.setVisibility(View.INVISIBLE);
imageView2.setVisibility(View.INVISIBLE);
imageView3.setVisibility(View.INVISIBLE);
imageView4.setVisibility(View.INVISIBLE);
imageView5.setVisibility(View.INVISIBLE);
imageView6.setVisibility(View.INVISIBLE);
clicked = "null"; clicked = "null";
red_btn.setEnabled(true); red_btn.setEnabled(true);
radomTimer = random.nextInt(5); radomTimer = random.nextInt(5);
...@@ -122,10 +155,78 @@ public class FocusedAttentionGame1 extends AppCompatActivity { ...@@ -122,10 +155,78 @@ public class FocusedAttentionGame1 extends AppCompatActivity {
} }
// appearance - 1s * 20 times // appearance - 1s * 20 times
else { else {
Log.d("***************radomTimer******************", String.valueOf(i + " 1000" )); Log.d("***************radomTimer******************", String.valueOf(i + " 3000" ));
imageView.setVisibility(View.VISIBLE);
if ( i == 22 ) {
unpickedNumbers.add(0);
unpickedNumbers.add(1);
unpickedNumbers.add(2);
unpickedNumbers.add(3);
unpickedNumbers.add(4);
unpickedNumbers.add(5);
unpickedNumbers.add(6);
unpickedNumbers.add(7);
unpickedNumbers.add(8);
unpickedNumbers.add(9);
}
rand = getRandomElement(unpickedNumbers);
if ( i == 2 || i == 14 || i == 26 || i == 38 ) {
imageView.setVisibility(View.VISIBLE);
imageView2.setVisibility(View.INVISIBLE);
imageView3.setVisibility(View.INVISIBLE);
imageView4.setVisibility(View.INVISIBLE);
imageView5.setVisibility(View.INVISIBLE);
imageView6.setVisibility(View.INVISIBLE);
imageView.setImageResource(images[rand]);
}
else if ( i == 4 || i == 16 || i == 28 || i == 40 ) {
imageView2.setVisibility(View.VISIBLE);
imageView.setVisibility(View.INVISIBLE);
imageView3.setVisibility(View.INVISIBLE);
imageView4.setVisibility(View.INVISIBLE);
imageView5.setVisibility(View.INVISIBLE);
imageView6.setVisibility(View.INVISIBLE);
imageView2.setImageResource(images[rand]);
}
else if ( i == 6 || i == 18 || i == 30 ) {
imageView3.setVisibility(View.VISIBLE);
imageView2.setVisibility(View.INVISIBLE);
imageView.setVisibility(View.INVISIBLE);
imageView4.setVisibility(View.INVISIBLE);
imageView5.setVisibility(View.INVISIBLE);
imageView6.setVisibility(View.INVISIBLE);
imageView3.setImageResource(images[rand]);
}
else if ( i == 8 || i == 20 || i == 32 ) {
imageView4.setVisibility(View.VISIBLE);
imageView2.setVisibility(View.INVISIBLE);
imageView3.setVisibility(View.INVISIBLE);
imageView.setVisibility(View.INVISIBLE);
imageView5.setVisibility(View.INVISIBLE);
imageView6.setVisibility(View.INVISIBLE);
imageView4.setImageResource(images[rand]);
}
else if ( i == 10 || i == 22 || i == 34 ) {
imageView5.setVisibility(View.VISIBLE);
imageView2.setVisibility(View.INVISIBLE);
imageView3.setVisibility(View.INVISIBLE);
imageView4.setVisibility(View.INVISIBLE);
imageView.setVisibility(View.INVISIBLE);
imageView6.setVisibility(View.INVISIBLE);
imageView5.setImageResource(images[rand]);
}
else if ( i == 12 || i == 24 || i == 36 ) {
imageView6.setVisibility(View.VISIBLE);
imageView2.setVisibility(View.INVISIBLE);
imageView3.setVisibility(View.INVISIBLE);
imageView4.setVisibility(View.INVISIBLE);
imageView5.setVisibility(View.INVISIBLE);
imageView.setVisibility(View.INVISIBLE);
imageView6.setImageResource(images[rand]);
}
red_btn.setEnabled(true); red_btn.setEnabled(true);
imageView.setImageResource(R.drawable.monkey);
clicked = "monkey"; clicked = "monkey";
startTime = System.currentTimeMillis(); startTime = System.currentTimeMillis();
imageView.postDelayed(this, 3000); imageView.postDelayed(this, 3000);
...@@ -225,6 +326,25 @@ public class FocusedAttentionGame1 extends AppCompatActivity { ...@@ -225,6 +326,25 @@ public class FocusedAttentionGame1 extends AppCompatActivity {
} }
// Function select an element base on index
// and return an element
public int getRandomElement(List<Integer> list) {
Random rand = new Random();
//int val = rand.nextInt(list.size());
int val = list.get(rand.nextInt(list.size()));
//list.remove("val");
Iterator itr = list.iterator();
while (itr.hasNext()) {
int data = (Integer)itr.next();
if (data == val)
itr.remove();
}
Log.d("1111111111111111111111111", val + "----" + list);
return val;
}
/*************************************************************************************************/ /*************************************************************************************************/
@Override @Override
......
...@@ -46,10 +46,66 @@ ...@@ -46,10 +46,66 @@
android:id="@+id/imageView" android:id="@+id/imageView"
android:layout_width="200dp" android:layout_width="200dp"
android:layout_height="200dp" android:layout_height="200dp"
android:layout_marginBottom="50dp" android:layout_marginBottom="48dp"
android:src="@drawable/monkey"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5" app:layout_constraintHorizontal_bias="0.54"
app:layout_constraintStart_toStartOf="parent" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginBottom="104dp"
android:src="@drawable/monkey"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.952"
app:layout_constraintStart_toStartOf="parent" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginBottom="48dp"
android:src="@drawable/monkey"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.03"
app:layout_constraintStart_toStartOf="parent" />
<ImageView
android:id="@+id/imageView4"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginBottom="140dp"
android:src="@drawable/monkey"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.318"
app:layout_constraintStart_toStartOf="parent" />
<ImageView
android:id="@+id/imageView5"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginBottom="4dp"
android:src="@drawable/monkey"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.726"
app:layout_constraintStart_toStartOf="parent" />
<ImageView
android:id="@+id/imageView6"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginBottom="4dp"
android:src="@drawable/monkey"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.246"
app:layout_constraintStart_toStartOf="parent" /> app:layout_constraintStart_toStartOf="parent" />
<ImageButton <ImageButton
......
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