Commit cd564fd2 authored by Anuththara18's avatar Anuththara18

Bug Fixing, Adding sounds to button clicks

parent a3b78743
......@@ -45,7 +45,8 @@
<activity
android:name=".alternating.AlternatingAttentionGame1"
android:screenOrientation="landscape"
android:theme="@style/Theme.AppCompat.NoActionBar"></activity>
android:theme="@style/Theme.AppCompat.NoActionBar">
</activity>
<provider
android:name="androidx.core.content.FileProvider"
......@@ -58,9 +59,11 @@
</provider>
<activity
android:name=".selective.BirdChoosingActivity"
android:name=".sustained.BirdChoosingActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar" />
android:theme="@style/Theme.AppCompat.NoActionBar" >
</activity>
<activity
android:name=".dividedattention.DACompleteScreen"
android:screenOrientation="portrait"
......@@ -93,7 +96,6 @@
android:name=".CompleteScreen2"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar" >
</activity>
<activity
android:name=".CompleteScreen"
......@@ -104,19 +106,25 @@
<activity
android:name=".dividedattention.DividedAttentionGame1"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar" />
android:theme="@style/Theme.AppCompat.NoActionBar" >
</activity>
<activity
android:name=".sustained.SustainedAttentionGame1"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar" />
android:theme="@style/Theme.AppCompat.NoActionBar" >
</activity>
<activity
android:name=".focused.FocusedAttentionGame2"
android:screenOrientation="landscape"
android:theme="@style/Theme.AppCompat.NoActionBar" />
android:theme="@style/Theme.AppCompat.NoActionBar" >
</activity>
<activity
android:name=".map.Map2Activity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar" />
android:theme="@style/Theme.AppCompat.NoActionBar" >
</activity>
<activity
android:name=".map.Map1Activity"
android:screenOrientation="portrait"
......@@ -129,7 +137,8 @@
<activity
android:name=".focused.FocusedAttentionGame1"
android:screenOrientation="landscape"
android:theme="@style/Theme.AppCompat.NoActionBar" />
android:theme="@style/Theme.AppCompat.NoActionBar" >
</activity>
<activity
android:name=".loginregistration.RegistrationActivity"
android:screenOrientation="portrait"
......@@ -153,7 +162,9 @@
<activity
android:name=".selective.SelectiveAttentionGame1"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar" />
android:theme="@style/Theme.AppCompat.NoActionBar" >
</activity>
<activity
android:name=".splashscreen.SplashActivity"
android:screenOrientation="landscape"
......
......@@ -84,7 +84,7 @@ public class AlternatingAttentionGame1 extends AppCompatActivity {
//Integer[] sequence1 = { 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0};
MediaPlayer mp;
MediaPlayer mp, mp2, mp3;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -154,6 +154,8 @@ public class AlternatingAttentionGame1 extends AppCompatActivity {
leftcount = 0;
}
imageView1.setImageResource(left_images[leftcount]);
red_btn_left.setEnabled(true);
red_btn_right.setEnabled(true);
leftcount++;
startTime = System.currentTimeMillis();
clickedSide = "left";
......@@ -172,6 +174,8 @@ public class AlternatingAttentionGame1 extends AppCompatActivity {
rightcount = 0;
}
imageView2.setImageResource(right_images[rightcount]);
red_btn_left.setEnabled(true);
red_btn_right.setEnabled(true);
rightcount++;
startTime = System.currentTimeMillis();
clickedSide = "right";
......@@ -220,6 +224,8 @@ public class AlternatingAttentionGame1 extends AppCompatActivity {
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.start();
break;
}
case MotionEvent.ACTION_UP:
......@@ -230,6 +236,7 @@ public class AlternatingAttentionGame1 extends AppCompatActivity {
totalReactionTime = totalReactionTime + reactionTime;
Log.d("correct " , startTime + " " + clickedTime + " " + reactionTime);
noOfCorrectResponses++;
red_btn_left.setEnabled(false);
}
else {
Log.d( "wrong" , startTime + " " + clickedTime + " " + reactionTime);
......@@ -253,6 +260,8 @@ public class AlternatingAttentionGame1 extends AppCompatActivity {
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.start();
break;
}
case MotionEvent.ACTION_UP:
......@@ -263,6 +272,7 @@ public class AlternatingAttentionGame1 extends AppCompatActivity {
totalReactionTime = totalReactionTime + reactionTime;
Log.d("correct " , startTime + " " + clickedTime + " " + reactionTime);
noOfCorrectResponses++;
red_btn_right.setEnabled(false);
}
else {
Log.d( "wrong" , startTime + " " + clickedTime + " " + reactionTime);
......
......@@ -67,7 +67,7 @@ public class DividedAttentionGame1 extends AppCompatActivity {
R.color.green, R.color.pink, R.color.purple,
R.color.orange, R.color.teal};
MediaPlayer mp;
MediaPlayer mp, mp2;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -129,47 +129,59 @@ public class DividedAttentionGame1 extends AppCompatActivity {
if ( j.equals("0") || j.equals("8") || j.equals("16") || j.equals("24") || j.equals("32") || j.equals("40") ) {
sq2.setImageResource(image[0]);
red_btn.setEnabled(true);
sq2.setTag(image[0]);
}
else if ( j.equals("1") || j.equals("9") || j.equals("17") || j.equals("25") || j.equals("33") || j.equals("41") ) {
sq2.setImageResource(image[1]);
red_btn.setEnabled(true);
sq2.setTag(image[1]);
}
else if ( j.equals("2") || j.equals("10") || j.equals("18") || j.equals("26") || j.equals("34") || j.equals("42") ) {
sq2.setImageResource(image[2]);
red_btn.setEnabled(true);
sq2.setTag(image[2]);
}
else if ( j.equals("3") || j.equals("11") || j.equals("19") || j.equals("27") || j.equals("35") || j.equals("43") ) {
sq2.setImageResource(image[3]);
red_btn.setEnabled(true);
sq2.setTag(image[3]);
}
else if ( j.equals("4") || j.equals("12") || j.equals("20") || j.equals("28") || j.equals("36") || j.equals("44") ) {
sq2.setImageResource(image[4]);
red_btn.setEnabled(true);
sq2.setTag(image[4]);
}
else if ( j.equals("5") || j.equals("13") || j.equals("21") || j.equals("29") || j.equals("37") || j.equals("45") ) {
sq2.setImageResource(image[5]);
red_btn.setEnabled(true);
sq2.setTag(image[5]);
}
else if ( j.equals("6") || j.equals("14") || j.equals("22") || j.equals("30") || j.equals("38") || j.equals("46") ) {
sq2.setImageResource(image[6]);
red_btn.setEnabled(true);
sq2.setTag(image[6]);
}
else if ( j.equals("7") || j.equals("15") || j.equals("23") || j.equals("31") || j.equals("39") || j.equals("47") ) {
sq2.setImageResource(image[7]);
red_btn.setEnabled(true);
sq2.setTag(image[7]);
}
startTime = System.currentTimeMillis();
sq2.postDelayed(this, 3000);
sq2.postDelayed(this, 2000);
Log.d("int", String.valueOf(i));
duration = duration + 3000;
duration = duration + 2000;
i++;
}
else {
long gameEnd = System.currentTimeMillis();
long seconds = (gameEnd - gameStart) / 1000;
//meanReactionTime = totalReactionTime / noOfCorrectResponses;
meanReactionTime = totalReactionTime;
if ( noOfCorrectResponses == 0 ) {
meanReactionTime = 0;
}
else {
meanReactionTime = (int) Math.ceil(totalReactionTime / noOfCorrectResponses); // ms
}
Log.d("****************************************************", "****************************************************");
Log.d("Game Time", String.valueOf(seconds));
Log.d("total", String.valueOf(totalCorrectResponses));
......@@ -198,6 +210,8 @@ public class DividedAttentionGame1 extends AppCompatActivity {
case MotionEvent.ACTION_DOWN: {
red_btn.getBackground().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
view.invalidate();
mp2 = MediaPlayer.create(getApplicationContext(), R.raw.button_click);
mp2.start();
break;
}
case MotionEvent.ACTION_UP:
......@@ -208,6 +222,7 @@ public class DividedAttentionGame1 extends AppCompatActivity {
totalReactionTime = totalReactionTime + reactionTime;
Log.d("correct " , startTime + " " + clickedTime + " " + reactionTime);
noOfCorrectResponses++;
red_btn.setEnabled(false);
}
else {
Log.d( "wrong" , startTime + " " + clickedTime + " " + reactionTime);
......
......@@ -67,9 +67,11 @@ public class FocusedAttentionGame1 extends AppCompatActivity {
ImageButton red_btn;
TextView textView;
String clicked = "null";
Integer[] isi = { 3000, 3500, 4000, 4500, 5000, 5500, 6000 };
MediaPlayer mp;
MediaPlayer mp, mp2;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -109,6 +111,8 @@ public class FocusedAttentionGame1 extends AppCompatActivity {
if ( i % 2 != 0 ) {
imageView.setVisibility(View.INVISIBLE);
clicked = "null";
red_btn.setEnabled(true);
radomTimer = random.nextInt(5);
updateInterval = isi[radomTimer];
imageView.postDelayed(this, updateInterval);
......@@ -120,11 +124,13 @@ public class FocusedAttentionGame1 extends AppCompatActivity {
else {
Log.d("***************radomTimer******************", String.valueOf(i + " 1000" ));
imageView.setVisibility(View.VISIBLE);
red_btn.setEnabled(true);
imageView.setImageResource(R.drawable.monkey);
clicked = "monkey";
startTime = System.currentTimeMillis();
imageView.postDelayed(this, 1000);
imageView.postDelayed(this, 3000);
totalCorrectResponses++;
duration = duration + 1000;
duration = duration + 3000;
i++;
}
......@@ -164,19 +170,21 @@ public class FocusedAttentionGame1 extends AppCompatActivity {
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN: {
red_btn.getBackground().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
view.invalidate();
mp2 = MediaPlayer.create(getApplicationContext(), R.raw.button_click);
mp2.start();
break;
}
case MotionEvent.ACTION_UP:
// Your action here on button click
clickedTime = System.currentTimeMillis();
reactionTime = ( clickedTime - startTime );
if (reactionTime < 4000) {
if (clicked.equals("monkey")) {
totalReactionTime = totalReactionTime + reactionTime;
Log.d("correct " , startTime + " " + clickedTime + " " + reactionTime);
noOfCorrectResponses++;
red_btn.setEnabled(false);
}
else {
Log.d( "wrong" , startTime + " " + clickedTime + " " + reactionTime);
......
......@@ -17,10 +17,7 @@ import com.anuththara18.attentionassessment.alternating.AlternatingAttentionGame
import com.anuththara18.attentionassessment.dividedattention.DividedAttentionGame1;
import com.anuththara18.attentionassessment.focused.FocusedAttentionGame1;
import com.anuththara18.attentionassessment.map.Map2Activity;
import com.anuththara18.attentionassessment.selective.BirdChoosingActivity;
import com.anuththara18.attentionassessment.selective.SelectiveAttentionGame1;
import com.anuththara18.attentionassessment.sustained.SustainedAttentionGame1;
import com.anuththara18.attentionassessment.sustained.SustainedAttentionGame2;
import com.anuththara18.attentionassessment.sustained.BirdChoosingActivity;
@SuppressLint("ValidFragment")
......@@ -46,7 +43,7 @@ public class MainFragment extends Fragment {
selectiveAttention = view.findViewById(R.id.selectiveAttention);
dividedAttention = view.findViewById(R.id.dividedAttention);
sustainedAttention = view.findViewById(R.id.sustainedAttention);
alternatingAttention = view.findViewById(R.id.alternatingAttention);
//alternatingAttention = view.findViewById(R.id.alternatingAttention);
alternatingAttention2 = view.findViewById(R.id.alternatingAttention2);
final MediaPlayer mp = MediaPlayer.create(getContext(), R.raw.button1);
......@@ -87,14 +84,6 @@ public class MainFragment extends Fragment {
}
});
alternatingAttention.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mp.start();
Intent intent = new Intent(getContext(), SustainedAttentionGame2.class);
startActivity(intent);
}
});
alternatingAttention2.setOnClickListener(new View.OnClickListener() {
@Override
......@@ -109,6 +98,7 @@ public class MainFragment extends Fragment {
}
}
/*
public class FirstFragment extends Fragment {
......
package com.anuththara18.attentionassessment.home;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.Toast;
import com.anuththara18.attentionassessment.R;
import com.anuththara18.attentionassessment.consentform.ConsentFormActivity;
import com.google.android.material.navigation.NavigationView;
import static android.Manifest.permission.MANAGE_EXTERNAL_STORAGE;
import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
public class NavigationDrawerActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener{
//FOR DESIGN
......@@ -31,6 +40,9 @@ public class NavigationDrawerActivity extends AppCompatActivity implements Navig
//FOR DATAS
private static final int FRAGMENT_MAINDASHBOARD = 0;
// constant code for runtime permissions
private static final int PERMISSION_REQUEST_CODE = 200;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -44,6 +56,14 @@ public class NavigationDrawerActivity extends AppCompatActivity implements Navig
// Show First Fragment
this.showFirstFragment();
// below code is used for
// checking our permissions.
if (checkPermission()) {
//Toast.makeText(this, "Permission Granted", Toast.LENGTH_SHORT).show();
} else {
requestPermission();
}
}
@Override
......@@ -107,6 +127,8 @@ public class NavigationDrawerActivity extends AppCompatActivity implements Navig
return true;
}
/**************************************************************************************************/
private void logout() {
//closing activity
......@@ -117,9 +139,7 @@ public class NavigationDrawerActivity extends AppCompatActivity implements Navig
}
// ---------------------
// CONFIGURATION
// ---------------------
/**************************************************************************************************/
// Configure Toolbar
private void configureToolBar(){
......@@ -127,6 +147,8 @@ public class NavigationDrawerActivity extends AppCompatActivity implements Navig
setSupportActionBar(toolbar);
}
/**************************************************************************************************/
//Configure Drawer Layout
private void configureDrawerLayout(){
this.drawerLayout = (DrawerLayout) findViewById(R.id.activity_main_drawer_layout);
......@@ -135,15 +157,15 @@ public class NavigationDrawerActivity extends AppCompatActivity implements Navig
toggle.syncState();
}
/**************************************************************************************************/
//Configure NavigationView
private void configureNavigationView(){
this.navigationView = (NavigationView) findViewById(R.id.activity_main_nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
// ---------------------
// FRAGMENTS
// ---------------------
/**************************************************************************************************/
// Show first fragment when activity is created
private void showFirstFragment(){
......@@ -156,8 +178,9 @@ public class NavigationDrawerActivity extends AppCompatActivity implements Navig
}
}
// Show fragment according an Identifier
/**************************************************************************************************/
// Show fragment according an Identifier
private void showFragment(int fragmentIdentifier){
switch (fragmentIdentifier){
case FRAGMENT_MAINDASHBOARD :
......@@ -180,7 +203,7 @@ public class NavigationDrawerActivity extends AppCompatActivity implements Navig
}
}
// ---
/**************************************************************************************************/
// Create each fragment page and show it
......@@ -189,8 +212,7 @@ public class NavigationDrawerActivity extends AppCompatActivity implements Navig
this.startTransactionFragment(this.fragmentMainDashboard);
}
// ---
/**************************************************************************************************/
// Generic method that will replace and show a fragment inside the MainActivity Frame Layout
private void startTransactionFragment(Fragment fragment){
......@@ -199,4 +221,54 @@ public class NavigationDrawerActivity extends AppCompatActivity implements Navig
.replace(R.id.activity_main_frame_layout, fragment).commit();
}
}
/**************************************************************************************************/
private boolean checkPermission() {
// checking of permissions.
int permission1 = ContextCompat.checkSelfPermission(getApplicationContext(), WRITE_EXTERNAL_STORAGE);
int permission2 = ContextCompat.checkSelfPermission(getApplicationContext(), READ_EXTERNAL_STORAGE);
int permission3 = ContextCompat.checkSelfPermission(getApplicationContext(), MANAGE_EXTERNAL_STORAGE);
return permission1 == PackageManager.PERMISSION_GRANTED && permission2 == PackageManager.PERMISSION_GRANTED && permission3 == PackageManager.PERMISSION_GRANTED;
}
/**************************************************************************************************/
private void requestPermission() {
// requesting permissions if not provided.
ActivityCompat.requestPermissions(this, new String[]{WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE, MANAGE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == PERMISSION_REQUEST_CODE) {
if (grantResults.length > 0) {
/*
Intent intent = new Intent();
intent.setAction(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
Uri uri = Uri.fromParts("package", this.getPackageName(), null);
intent.setData(uri);
startActivity(intent);
*/
// after requesting permissions we are showing
// users a toast message of permission granted.
boolean writeStorage = grantResults[0] == PackageManager.PERMISSION_GRANTED;
boolean readStorage = grantResults[1] == PackageManager.PERMISSION_GRANTED;
if (writeStorage && readStorage) {
//Toast.makeText(this, "Permission Granted..", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Permission Denied.", Toast.LENGTH_SHORT).show();
finish();
}
}
}
}
/**************************************************************************************************/
}
\ No newline at end of file
......@@ -58,6 +58,8 @@ public class SelectiveAttentionGame1 extends AppCompatActivity {
ImageView main_img, cross_btn;
ImageButton imageButton;
ArrayList<GridModel> gridModelArrayList;
GVAdapter adapter;
public static ArrayList<Integer> correctResponses;
public static ArrayList<Integer> incorrectResponses;
public static int columns;
......@@ -87,6 +89,7 @@ public class SelectiveAttentionGame1 extends AppCompatActivity {
Random random;
MediaPlayer mp;
int clickCount = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -106,7 +109,7 @@ public class SelectiveAttentionGame1 extends AppCompatActivity {
cross_btn = (ImageView) findViewById(R.id.cross_btn);
textview = findViewById(R.id.textview);
textview.setText(LanguageSetter.getresources().getString(R.string.select));
//textview.setText(LanguageSetter.getresources().getString(R.string.select));
mp = MediaPlayer.create(getApplicationContext(), R.raw.selective);
mp.start();
......@@ -134,56 +137,6 @@ public class SelectiveAttentionGame1 extends AppCompatActivity {
g = R.drawable.pink_pig;
g1 = "pink_pig";
/*
// level 3 - 4 & 6 (2 same)
g = R.drawable.white_cow;
g1 = "white_cow";
h = R.drawable.brown_donkey;
h1 = "brown_donkey";
ii = R.drawable.grey_goat;
i1 = "grey_goat";
j = R.drawable.blue_elephant;
j1 = "blue_elephant";
k = R.drawable.blue_hippo;
k1 = "blue_hippo";
// level 4 - 4 (2 same) & 6 (3 same)
l = R.drawable.white_zebra;
l1 = "white_zebra";
m = R.drawable.orange_tiger;
m1 = "orange_tiger";
n = R.drawable.brown_ox;
n1 = "brown_ox";
o = R.drawable.green_dino;
o1 = "green_dino";
p = R.drawable.green_snake;
p1 = "green_snake";
q = R.drawable.green_croc;
q1 = "green_croc";
// level 5 - 5 (2 same) & 7 (4 same)
r = R.drawable.brown_lion;
r1 = "brown_lion";
s = R.drawable.grey_elephant;
s1 = "grey_elephant";
t = R.drawable.blue_peacock;
t1 = "blue_peacock";
u = R.drawable.yellow_chicken;
u1 = "yellow_chicken";
v = R.drawable.yellow_dino;
v1 = "yellow_dino";
w = R.drawable.yellow_girraffe;
w1 = "yellow_girraffe";
x = R.drawable.yellow_leapoard;
x1 = "yellow_leapoard";
y = R.drawable.white_cow;
y1 = "white_cow";
z = R.drawable.pink_pig;
z1 = "pink_pig";
*/
image = num = random.nextInt(100);
if ( age >= 4 && age <= 5 ) {
......@@ -203,13 +156,16 @@ public class SelectiveAttentionGame1 extends AppCompatActivity {
// 3 objects
num = random.nextInt(120);
if(num >= 0 && num < 40) {
main_img.setImageResource(c);
main_img.setImageResource(a);
image_name = a1;
}
else if(num >= 40 && num < 80) {
main_img.setImageResource(d);
main_img.setImageResource(b);
image_name = b1;
}
else if(num >= 80 && num < 120) {
main_img.setImageResource(e);
main_img.setImageResource(c);
image_name = c1;
}
}
else if (level == 3) {
......@@ -217,48 +173,61 @@ public class SelectiveAttentionGame1 extends AppCompatActivity {
num = random.nextInt(120);
if(num >= 0 && num < 30) {
main_img.setImageResource(a);
image_name = a1;
}
else if(num >= 30 && num < 60) {
main_img.setImageResource(b);
image_name = b1;
}
else if(num >= 60 && num < 90) {
main_img.setImageResource(c);
image_name = c1;
}
else if(num >= 90 && num < 120) {
main_img.setImageResource(d);
image_name = d1;
}
}
else if (level == 4) {
num = random.nextInt(120);
if(num >= 0 && num < 30) {
main_img.setImageResource(a);
image_name = a1;
}
else if(num >= 30 && num < 60) {
main_img.setImageResource(b);
image_name = b1;
}
else if(num >= 60 && num < 90) {
main_img.setImageResource(c);
image_name = c1;
}
else if(num >= 90 && num < 120) {
main_img.setImageResource(d);
image_name = d1;
}
}
else if (level == 5) {
num = random.nextInt(100);
if(num >= 0 && num < 20) {
main_img.setImageResource(a);
image_name = a1;
}
else if(num >= 20 && num < 40) {
main_img.setImageResource(b);
image_name = b1;
}
else if(num >= 40 && num < 60) {
main_img.setImageResource(c);
image_name = c1;
}
else if(num >= 60 && num < 80) {
main_img.setImageResource(d);
image_name = d1;
}
else if(num >= 80 && num < 100) {
main_img.setImageResource(e);
image_name = e1;
}
}
}
......@@ -269,139 +238,228 @@ public class SelectiveAttentionGame1 extends AppCompatActivity {
num = random.nextInt(120);
if (num >= 0 && num < 30) {
main_img.setImageResource(a);
} else if (num >= 30 && num < 60) {
image_name = a1;
}
else if (num >= 30 && num < 60) {
main_img.setImageResource(b);
} else if (num >= 60 && num < 90) {
image_name = b1;
}
else if (num >= 60 && num < 90) {
main_img.setImageResource(c);
} else if (num >= 90 && num < 120) {
image_name = c1;
}
else if (num >= 90 && num < 120) {
main_img.setImageResource(d);
image_name = d1;
}
} else if (level == 2) {
// 5 objects
num = random.nextInt(100);
if (num >= 0 && num < 20) {
main_img.setImageResource(a);
} else if (num >= 20 && num < 40) {
image_name = a1;
}
else if (num >= 20 && num < 40) {
main_img.setImageResource(b);
} else if (num >= 40 && num < 60) {
image_name = b1;
}
else if (num >= 40 && num < 60) {
main_img.setImageResource(c);
} else if (num >= 60 && num < 80) {
image_name = c1;
}
else if (num >= 60 && num < 80) {
main_img.setImageResource(d);
} else if (num >= 80 && num < 100) {
image_name = d1;
}
else if (num >= 80 && num < 100) {
main_img.setImageResource(e);
image_name = e1;
}
} else if (level == 3) {
// 6 objects
num = random.nextInt(120);
if (num >= 0 && num < 20) {
main_img.setImageResource(a);
image_name = a1;
} else if (num >= 20 && num < 40) {
main_img.setImageResource(b);
image_name = b1;
} else if (num >= 40 && num < 60) {
main_img.setImageResource(c);
image_name = c1;
} else if (num >= 60 && num < 80) {
main_img.setImageResource(d);
image_name = d1;
} else if (num >= 80 && num < 100) {
main_img.setImageResource(e);
image_name = e1;
} else if (num >= 100 && num < 120) {
main_img.setImageResource(f);
image_name = f1;
}
} else if (level == 4) {
// 6 objects
num = random.nextInt(120);
if (num >= 0 && num < 20) {
main_img.setImageResource(a);
image_name = a1;
} else if (num >= 20 && num < 40) {
main_img.setImageResource(b);
image_name = b1;
} else if (num >= 40 && num < 60) {
main_img.setImageResource(c);
image_name = c1;
} else if (num >= 60 && num < 80) {
main_img.setImageResource(d);
image_name = d1;
} else if (num >= 80 && num < 100) {
main_img.setImageResource(e);
image_name = e1;
} else if (num >= 100 && num < 120) {
main_img.setImageResource(f);
image_name = f1;
}
} else if (level == 5) {
// 7 objects
num = random.nextInt(140);
if (num >= 0 && num < 20) {
main_img.setImageResource(a);
image_name = a1;
} else if (num >= 20 && num < 40) {
main_img.setImageResource(b);
image_name = b1;
} else if (num >= 40 && num < 60) {
main_img.setImageResource(c);
image_name = c1;
} else if (num >= 60 && num < 80) {
main_img.setImageResource(d);
image_name = d1;
} else if (num >= 80 && num < 100) {
main_img.setImageResource(e);
image_name = e1;
} else if (num >= 100 && num < 120) {
main_img.setImageResource(f);
image_name = f1;
} else if (num >= 120 && num < 140) {
main_img.setImageResource(g);
image_name = g1;
}
}
}
/*
if ( age == 1 && level == 1 ) {
num = random.nextInt(120);
if(num >= 0 && num < 20) {
main_img.setImageResource(a);
image_name = a1;
}
else if(num >= 20 && num < 40) {
main_img.setImageResource(b);
image_name = b1;
getGridSize();
do {
totalCorrectResponses = 0;
formGrid();
for ( int i = 0; i < gridSize; i++) {
GridModel data = (GridModel) gridModelArrayList.get(i);
if ( data.getImage_name().equals(image_name)){
totalCorrectResponses++;
}
else if(num >= 40 && num < 60) {
main_img.setImageResource(c);
image_name = c1;
}
else if(num >= 60 && num < 80) {
main_img.setImageResource(d);
image_name = d1;
Log.d("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@", String.valueOf(totalCorrectResponses));
} while (totalCorrectResponses < 6);
try {
calendar = Calendar.getInstance();
simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
startDate = simpleDateFormat.parse(String.valueOf(simpleDateFormat.format(calendar.getTime())));
Log.d("startTime", String.valueOf(simpleDateFormat.format(calendar.getTime())));
} catch (ParseException parseException) {
parseException.printStackTrace();
}
else if(num >= 80 && num < 100) {
main_img.setImageResource(e);
image_name = e1;
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id) {
GridModel data = (GridModel) gridModelArrayList.get(position);
//Toast.makeText(SelectiveAttentionGame1.this, "" + position + data.getImage_name() + data.getImgid(), Toast.LENGTH_SHORT).show();
if ( data.getImage_name().equals(image_name) ) {
noOfCorrectResponses++;
correctResponses.add(position);
gridView.setAdapter(adapter);
}
else if(num >= 100 && num < 120) {
main_img.setImageResource(aa);
image_name = aa1;
else {
// incorrect clicks
noOfCommissionErrors++;
incorrectResponses.add(position);
gridView.setAdapter(adapter);
}
}
*/
});
getGridSize();
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ArrayList<GridModel> gridModelArrayList = new ArrayList<GridModel>();
if ( clickCount == 0 ) {
try {
calendar = Calendar.getInstance();
simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
endDate = simpleDateFormat.parse(String.valueOf(simpleDateFormat.format(calendar.getTime())));
Log.d("endTime", String.valueOf(simpleDateFormat.format(calendar.getTime())));
} catch (ParseException parseException) {
parseException.printStackTrace();
}
// missed clicks
noOfOmmissionErrors = totalCorrectResponses - noOfCorrectResponses;
Log.d("total", String.valueOf(totalCorrectResponses));
Log.d("correctResponses", String.valueOf(noOfCorrectResponses));
Log.d("omissionErrors", String.valueOf(totalCorrectResponses - noOfCorrectResponses));
Log.d("commissionErrors", String.valueOf(noOfCommissionErrors));
Log.d("duration", String.valueOf(getCompletionTime()));
for ( int i = 1; i <= gridSize; i++) {
completionTime = getCompletionTime();
/*
// 7 objects - 4 same coloured
num = random.nextInt(120);
if(num >= 0 && num < 20) {
gridModelArrayList.add(new GridModel(a1, a));
GVAdapter2 adapter = new GVAdapter2(getApplicationContext(), gridModelArrayList);
gridView.setAdapter(adapter);
saveDataToOnlineDB();
createTable();
saveDataToLocalDB();
clickCount++;
}
else if(num >= 20 && num < 40) {
gridModelArrayList.add(new GridModel(b1, b));
else {
Intent intent = new Intent(getApplicationContext(), SelectiveACompleteScreen.class);
finish();
mp.pause();
startActivity(intent);
}
else if(num >= 40 && num < 60) {
gridModelArrayList.add(new GridModel(c1, c));
}
else if(num >= 60 && num < 80) {
gridModelArrayList.add(new GridModel(d1, d));
});
cross_btn.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN: {
cross_btn.getBackground().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
view.invalidate();
break;
}
else if(num >= 80 && num < 100) {
gridModelArrayList.add(new GridModel(e1, e));
case MotionEvent.ACTION_UP:
alert();
mp.pause();
case MotionEvent.ACTION_CANCEL: {
cross_btn.getBackground().clearColorFilter();
view.invalidate();
break;
}
else if(num >= 100 && num < 120) {
gridModelArrayList.add(new GridModel(aa1, aa));
}
*/
return true;
}
});
}
/*************************************************************************************************/
private void formGrid() {
gridModelArrayList = new ArrayList<GridModel>();
for ( int i = 1; i <= gridSize; i++) {
if ( age >= 4 && age <= 5 ) {
if (level == 1) {
// 2 objects
......@@ -588,101 +646,9 @@ public class SelectiveAttentionGame1 extends AppCompatActivity {
}
GVAdapter adapter = new GVAdapter(this, gridModelArrayList);
adapter = new GVAdapter(this, gridModelArrayList);
gridView.setAdapter(adapter);
try {
calendar = Calendar.getInstance();
simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
startDate = simpleDateFormat.parse(String.valueOf(simpleDateFormat.format(calendar.getTime())));
Log.d("startTime", String.valueOf(simpleDateFormat.format(calendar.getTime())));
} catch (ParseException parseException) {
parseException.printStackTrace();
}
for ( int i = 0; i < gridSize; i++) {
GridModel data = (GridModel) gridModelArrayList.get(i);
if ( data.getImage_name().equals(image_name)){
totalCorrectResponses++;
}
}
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id) {
GridModel data = (GridModel) gridModelArrayList.get(position);
//Toast.makeText(SelectiveAttentionGame1.this, "" + position + data.getImage_name() + data.getImgid(), Toast.LENGTH_SHORT).show();
if ( data.getImage_name().equals(image_name) ) {
noOfCorrectResponses++;
correctResponses.add(position);
gridView.setAdapter(adapter);
}
else {
// incorrect clicks
noOfCommissionErrors++;
incorrectResponses.add(position);
gridView.setAdapter(adapter);
}
}
});
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
calendar = Calendar.getInstance();
simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
endDate = simpleDateFormat.parse(String.valueOf(simpleDateFormat.format(calendar.getTime())));
Log.d("endTime", String.valueOf(simpleDateFormat.format(calendar.getTime())));
} catch (ParseException parseException) {
parseException.printStackTrace();
}
// missed clicks
noOfOmmissionErrors = totalCorrectResponses - noOfCorrectResponses;
Log.d("total", String.valueOf(totalCorrectResponses));
Log.d("correctResponses", String.valueOf(noOfCorrectResponses));
Log.d("omissionErrors", String.valueOf(totalCorrectResponses - noOfCorrectResponses));
Log.d("commissionErrors", String.valueOf(noOfCommissionErrors));
Log.d("duration", String.valueOf(getCompletionTime()));
completionTime = getCompletionTime();
GVAdapter2 adapter = new GVAdapter2(getApplicationContext(), gridModelArrayList);
gridView.setAdapter(adapter);
saveDataToOnlineDB();
createTable();
saveDataToLocalDB();
Intent intent = new Intent(getApplicationContext(), SelectiveACompleteScreen.class);
finish();
mp.pause();
startActivity(intent);
}
});
cross_btn.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN: {
cross_btn.getBackground().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
view.invalidate();
break;
}
case MotionEvent.ACTION_UP:
alert();
mp.pause();
case MotionEvent.ACTION_CANCEL: {
cross_btn.getBackground().clearColorFilter();
view.invalidate();
break;
}
}
return true;
}
});
}
/*************************************************************************************************/
......
package com.anuththara18.attentionassessment.selective;
package com.anuththara18.attentionassessment.sustained;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
......@@ -9,14 +9,12 @@ import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.anuththara18.attentionassessment.R;
import com.anuththara18.attentionassessment.language.LanguageSetter;
import com.anuththara18.attentionassessment.sustained.SustainedAttentionGame1;
public class BirdChoosingActivity extends AppCompatActivity {
......@@ -50,7 +48,7 @@ public class BirdChoosingActivity extends AppCompatActivity {
l3 = findViewById(R.id.l3);
l4 = findViewById(R.id.l4);
textView8.setText(LanguageSetter.getresources().getString(R.string.birdselect));
//textView8.setText(LanguageSetter.getresources().getString(R.string.birdselect));
bird1.setOnClickListener(new View.OnClickListener() {
@Override
......
......@@ -7,25 +7,19 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.PorterDuff;
import android.graphics.drawable.AnimationDrawable;
import android.media.MediaPlayer;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.anuththara18.attentionassessment.CompleteScreen2;
import com.anuththara18.attentionassessment.R;
import com.anuththara18.attentionassessment.age.AgeActivity;
import com.anuththara18.attentionassessment.db.Api;
......@@ -33,14 +27,11 @@ import com.anuththara18.attentionassessment.db.RequestHandler;
import com.anuththara18.attentionassessment.gender.GenderActivity;
import com.anuththara18.attentionassessment.home.NavigationDrawerActivity;
import com.anuththara18.attentionassessment.language.LanguageSetter;
import com.anuththara18.attentionassessment.selective.BirdChoosingActivity;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
public class SustainedAttentionGame1 extends AppCompatActivity {
......@@ -57,12 +48,12 @@ public class SustainedAttentionGame1 extends AppCompatActivity {
// isi = 10 - 60 secs
Integer[] isi = { 10000, 45000, 25000, 50000, 20000, 35000, 60000, 15000, 30000, 55000, 40000,
/*Integer[] isi = { 10000, 45000, 25000, 50000, 20000, 35000, 60000, 15000, 30000, 55000, 40000,
10000, 45000, 25000, 50000, 20000, 35000, 60000, 15000, 30000, 55000, 40000,
10000, 15000, 10000, 15000 };
/*Integer[] isi = { 1000, 4500, 2500, 5000, 2000, 3500, 6000, 1500, 3000, 5500, 4000,
10000, 15000, 10000, 15000 };*/
Integer[] isi = { 1000, 4500, 2500, 5000, 2000, 3500, 6000, 1500, 3000, 5500, 4000,
1000, 4500, 2500, 5000, 2000, 3500, 6000, 1500, 3000, 5500, 4000,
1000, 1500, 1000, 1500 };*/
1000, 1500, 1000, 1500 };
Integer[] image = { R.drawable.red_bird_gif,
R.drawable.blue_bird_gif,
......@@ -88,7 +79,7 @@ public class SustainedAttentionGame1 extends AppCompatActivity {
long totalReactionTime = 0;
int meanReactionTime = 0;
MediaPlayer mp;
MediaPlayer mp, mp2;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -134,6 +125,7 @@ public class SustainedAttentionGame1 extends AppCompatActivity {
randomImage = random.nextInt(6);
bird.setVisibility(View.INVISIBLE);
gifImageView.setVisibility(View.VISIBLE);
red_btn.setEnabled(true);
gifImageView.setImageResource(image[randomImage]);
clickedImage = image[randomImage];
updateInterval = isi[j];
......@@ -145,7 +137,7 @@ public class SustainedAttentionGame1 extends AppCompatActivity {
}
// appearance - 0.5s * 25 times
else if ( totalCorrectResponses <= 25 ) {
Log.d("radomTimer", String.valueOf(i + " 2000" ));
Log.d("radomTimer", String.valueOf(i + " 3000" ));
Log.d("******************************", "start 1");
if (BirdChoosingActivity.birdSelected == 1) {
......@@ -167,11 +159,12 @@ public class SustainedAttentionGame1 extends AppCompatActivity {
}
bird.setVisibility(View.VISIBLE);
red_btn.setEnabled(true);
gifImageView.setVisibility(View.INVISIBLE);
startTime = System.currentTimeMillis();
gifImageView.postDelayed(this, 2000);
gifImageView.postDelayed(this, 3000);
totalCorrectResponses++;
duration = duration + 2000;
duration = duration + 3000;
i++;
}
......@@ -219,15 +212,13 @@ public class SustainedAttentionGame1 extends AppCompatActivity {
public void onClick(View view) {
clickedTime = System.currentTimeMillis();
reactionTime = ( clickedTime - startTime );
mp2 = MediaPlayer.create(getApplicationContext(), R.raw.button_click);
mp2.start();
if (correctImage == clickedImage) {
totalReactionTime = (long) (totalReactionTime + reactionTime);
Log.d("correct " , startTime + " " + clickedTime + " " + reactionTime);
noOfCorrectResponses++;
}
else if (reactionTime < 4000) {
totalReactionTime = (long) (totalReactionTime + reactionTime);
Log.d("correct " , startTime + " " + clickedTime + " " + reactionTime);
noOfCorrectResponses++;
red_btn.setEnabled(false);
}
else {
noOfCommissionErrors++;
......
......@@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg5"
tools:context=".selective.BirdChoosingActivity">
tools:context=".sustained.BirdChoosingActivity">
<ImageButton
android:id="@+id/cross_btn"
......
......@@ -221,7 +221,7 @@
android:textSize="20dp"
android:layout_marginRight="15dp"
android:fontFamily="@font/aclonica"
android:text="Sustained Attention I"
android:text="Sustained Attention"
android:textStyle="bold"/>
<ImageView
......@@ -235,6 +235,8 @@
</androidx.cardview.widget.CardView>
<!--
<androidx.cardview.widget.CardView
android:id="@+id/alternatingAttention"
android:layout_height="200dp"
......@@ -290,6 +292,8 @@
</androidx.cardview.widget.CardView>
-->
<androidx.cardview.widget.CardView
android:id="@+id/alternatingAttention2"
android:layout_height="200dp"
......
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