Commit cd564fd2 authored by Anuththara18's avatar Anuththara18

Bug Fixing, Adding sounds to button clicks

parent a3b78743
...@@ -45,7 +45,8 @@ ...@@ -45,7 +45,8 @@
<activity <activity
android:name=".alternating.AlternatingAttentionGame1" android:name=".alternating.AlternatingAttentionGame1"
android:screenOrientation="landscape" android:screenOrientation="landscape"
android:theme="@style/Theme.AppCompat.NoActionBar"></activity> android:theme="@style/Theme.AppCompat.NoActionBar">
</activity>
<provider <provider
android:name="androidx.core.content.FileProvider" android:name="androidx.core.content.FileProvider"
...@@ -58,9 +59,11 @@ ...@@ -58,9 +59,11 @@
</provider> </provider>
<activity <activity
android:name=".selective.BirdChoosingActivity" android:name=".sustained.BirdChoosingActivity"
android:screenOrientation="portrait" android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar" /> android:theme="@style/Theme.AppCompat.NoActionBar" >
</activity>
<activity <activity
android:name=".dividedattention.DACompleteScreen" android:name=".dividedattention.DACompleteScreen"
android:screenOrientation="portrait" android:screenOrientation="portrait"
...@@ -93,7 +96,6 @@ ...@@ -93,7 +96,6 @@
android:name=".CompleteScreen2" android:name=".CompleteScreen2"
android:screenOrientation="portrait" android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar" > android:theme="@style/Theme.AppCompat.NoActionBar" >
</activity> </activity>
<activity <activity
android:name=".CompleteScreen" android:name=".CompleteScreen"
...@@ -104,19 +106,25 @@ ...@@ -104,19 +106,25 @@
<activity <activity
android:name=".dividedattention.DividedAttentionGame1" android:name=".dividedattention.DividedAttentionGame1"
android:screenOrientation="portrait" android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar" /> android:theme="@style/Theme.AppCompat.NoActionBar" >
</activity>
<activity <activity
android:name=".sustained.SustainedAttentionGame1" android:name=".sustained.SustainedAttentionGame1"
android:screenOrientation="portrait" android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar" /> android:theme="@style/Theme.AppCompat.NoActionBar" >
</activity>
<activity <activity
android:name=".focused.FocusedAttentionGame2" android:name=".focused.FocusedAttentionGame2"
android:screenOrientation="landscape" android:screenOrientation="landscape"
android:theme="@style/Theme.AppCompat.NoActionBar" /> android:theme="@style/Theme.AppCompat.NoActionBar" >
</activity>
<activity <activity
android:name=".map.Map2Activity" android:name=".map.Map2Activity"
android:screenOrientation="portrait" android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar" /> android:theme="@style/Theme.AppCompat.NoActionBar" >
</activity>
<activity <activity
android:name=".map.Map1Activity" android:name=".map.Map1Activity"
android:screenOrientation="portrait" android:screenOrientation="portrait"
...@@ -129,7 +137,8 @@ ...@@ -129,7 +137,8 @@
<activity <activity
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" >
</activity>
<activity <activity
android:name=".loginregistration.RegistrationActivity" android:name=".loginregistration.RegistrationActivity"
android:screenOrientation="portrait" android:screenOrientation="portrait"
...@@ -153,7 +162,9 @@ ...@@ -153,7 +162,9 @@
<activity <activity
android:name=".selective.SelectiveAttentionGame1" android:name=".selective.SelectiveAttentionGame1"
android:screenOrientation="portrait" android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar" /> android:theme="@style/Theme.AppCompat.NoActionBar" >
</activity>
<activity <activity
android:name=".splashscreen.SplashActivity" android:name=".splashscreen.SplashActivity"
android:screenOrientation="landscape" android:screenOrientation="landscape"
......
...@@ -84,7 +84,7 @@ public class AlternatingAttentionGame1 extends AppCompatActivity { ...@@ -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}; //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 @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -154,6 +154,8 @@ public class AlternatingAttentionGame1 extends AppCompatActivity { ...@@ -154,6 +154,8 @@ public class AlternatingAttentionGame1 extends AppCompatActivity {
leftcount = 0; leftcount = 0;
} }
imageView1.setImageResource(left_images[leftcount]); imageView1.setImageResource(left_images[leftcount]);
red_btn_left.setEnabled(true);
red_btn_right.setEnabled(true);
leftcount++; leftcount++;
startTime = System.currentTimeMillis(); startTime = System.currentTimeMillis();
clickedSide = "left"; clickedSide = "left";
...@@ -172,6 +174,8 @@ public class AlternatingAttentionGame1 extends AppCompatActivity { ...@@ -172,6 +174,8 @@ public class AlternatingAttentionGame1 extends AppCompatActivity {
rightcount = 0; rightcount = 0;
} }
imageView2.setImageResource(right_images[rightcount]); imageView2.setImageResource(right_images[rightcount]);
red_btn_left.setEnabled(true);
red_btn_right.setEnabled(true);
rightcount++; rightcount++;
startTime = System.currentTimeMillis(); startTime = System.currentTimeMillis();
clickedSide = "right"; clickedSide = "right";
...@@ -220,6 +224,8 @@ public class AlternatingAttentionGame1 extends AppCompatActivity { ...@@ -220,6 +224,8 @@ public class AlternatingAttentionGame1 extends AppCompatActivity {
case MotionEvent.ACTION_DOWN: { case MotionEvent.ACTION_DOWN: {
red_btn_left.getBackground().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP); red_btn_left.getBackground().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
view.invalidate(); view.invalidate();
mp2 = MediaPlayer.create(getApplicationContext(), R.raw.button_click);
mp2.start();
break; break;
} }
case MotionEvent.ACTION_UP: case MotionEvent.ACTION_UP:
...@@ -230,6 +236,7 @@ public class AlternatingAttentionGame1 extends AppCompatActivity { ...@@ -230,6 +236,7 @@ public class AlternatingAttentionGame1 extends AppCompatActivity {
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);
} }
else { else {
Log.d( "wrong" , startTime + " " + clickedTime + " " + reactionTime); Log.d( "wrong" , startTime + " " + clickedTime + " " + reactionTime);
...@@ -253,6 +260,8 @@ public class AlternatingAttentionGame1 extends AppCompatActivity { ...@@ -253,6 +260,8 @@ public class AlternatingAttentionGame1 extends AppCompatActivity {
case MotionEvent.ACTION_DOWN: { case MotionEvent.ACTION_DOWN: {
red_btn_right.getBackground().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP); red_btn_right.getBackground().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
view.invalidate(); view.invalidate();
mp3 = MediaPlayer.create(getApplicationContext(), R.raw.button_click);
mp3.start();
break; break;
} }
case MotionEvent.ACTION_UP: case MotionEvent.ACTION_UP:
...@@ -263,6 +272,7 @@ public class AlternatingAttentionGame1 extends AppCompatActivity { ...@@ -263,6 +272,7 @@ public class AlternatingAttentionGame1 extends AppCompatActivity {
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);
} }
else { else {
Log.d( "wrong" , startTime + " " + clickedTime + " " + reactionTime); Log.d( "wrong" , startTime + " " + clickedTime + " " + reactionTime);
......
...@@ -67,7 +67,7 @@ public class DividedAttentionGame1 extends AppCompatActivity { ...@@ -67,7 +67,7 @@ public class DividedAttentionGame1 extends AppCompatActivity {
R.color.green, R.color.pink, R.color.purple, R.color.green, R.color.pink, R.color.purple,
R.color.orange, R.color.teal}; R.color.orange, R.color.teal};
MediaPlayer mp; MediaPlayer mp, mp2;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -129,47 +129,59 @@ public class DividedAttentionGame1 extends AppCompatActivity { ...@@ -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") ) { if ( j.equals("0") || j.equals("8") || j.equals("16") || j.equals("24") || j.equals("32") || j.equals("40") ) {
sq2.setImageResource(image[0]); sq2.setImageResource(image[0]);
red_btn.setEnabled(true);
sq2.setTag(image[0]); sq2.setTag(image[0]);
} }
else if ( j.equals("1") || j.equals("9") || j.equals("17") || j.equals("25") || j.equals("33") || j.equals("41") ) { else if ( j.equals("1") || j.equals("9") || j.equals("17") || j.equals("25") || j.equals("33") || j.equals("41") ) {
sq2.setImageResource(image[1]); sq2.setImageResource(image[1]);
red_btn.setEnabled(true);
sq2.setTag(image[1]); sq2.setTag(image[1]);
} }
else if ( j.equals("2") || j.equals("10") || j.equals("18") || j.equals("26") || j.equals("34") || j.equals("42") ) { else if ( j.equals("2") || j.equals("10") || j.equals("18") || j.equals("26") || j.equals("34") || j.equals("42") ) {
sq2.setImageResource(image[2]); sq2.setImageResource(image[2]);
red_btn.setEnabled(true);
sq2.setTag(image[2]); sq2.setTag(image[2]);
} }
else if ( j.equals("3") || j.equals("11") || j.equals("19") || j.equals("27") || j.equals("35") || j.equals("43") ) { else if ( j.equals("3") || j.equals("11") || j.equals("19") || j.equals("27") || j.equals("35") || j.equals("43") ) {
sq2.setImageResource(image[3]); sq2.setImageResource(image[3]);
red_btn.setEnabled(true);
sq2.setTag(image[3]); sq2.setTag(image[3]);
} }
else if ( j.equals("4") || j.equals("12") || j.equals("20") || j.equals("28") || j.equals("36") || j.equals("44") ) { else if ( j.equals("4") || j.equals("12") || j.equals("20") || j.equals("28") || j.equals("36") || j.equals("44") ) {
sq2.setImageResource(image[4]); sq2.setImageResource(image[4]);
red_btn.setEnabled(true);
sq2.setTag(image[4]); sq2.setTag(image[4]);
} }
else if ( j.equals("5") || j.equals("13") || j.equals("21") || j.equals("29") || j.equals("37") || j.equals("45") ) { else if ( j.equals("5") || j.equals("13") || j.equals("21") || j.equals("29") || j.equals("37") || j.equals("45") ) {
sq2.setImageResource(image[5]); sq2.setImageResource(image[5]);
red_btn.setEnabled(true);
sq2.setTag(image[5]); sq2.setTag(image[5]);
} }
else if ( j.equals("6") || j.equals("14") || j.equals("22") || j.equals("30") || j.equals("38") || j.equals("46") ) { else if ( j.equals("6") || j.equals("14") || j.equals("22") || j.equals("30") || j.equals("38") || j.equals("46") ) {
sq2.setImageResource(image[6]); sq2.setImageResource(image[6]);
red_btn.setEnabled(true);
sq2.setTag(image[6]); sq2.setTag(image[6]);
} }
else if ( j.equals("7") || j.equals("15") || j.equals("23") || j.equals("31") || j.equals("39") || j.equals("47") ) { else if ( j.equals("7") || j.equals("15") || j.equals("23") || j.equals("31") || j.equals("39") || j.equals("47") ) {
sq2.setImageResource(image[7]); sq2.setImageResource(image[7]);
red_btn.setEnabled(true);
sq2.setTag(image[7]); sq2.setTag(image[7]);
} }
startTime = System.currentTimeMillis(); startTime = System.currentTimeMillis();
sq2.postDelayed(this, 3000); sq2.postDelayed(this, 2000);
Log.d("int", String.valueOf(i)); Log.d("int", String.valueOf(i));
duration = duration + 3000; duration = duration + 2000;
i++; i++;
} }
else { else {
long gameEnd = System.currentTimeMillis(); long gameEnd = System.currentTimeMillis();
long seconds = (gameEnd - gameStart) / 1000; long seconds = (gameEnd - gameStart) / 1000;
//meanReactionTime = totalReactionTime / noOfCorrectResponses; if ( noOfCorrectResponses == 0 ) {
meanReactionTime = totalReactionTime; meanReactionTime = 0;
}
else {
meanReactionTime = (int) Math.ceil(totalReactionTime / noOfCorrectResponses); // ms
}
Log.d("****************************************************", "****************************************************"); Log.d("****************************************************", "****************************************************");
Log.d("Game Time", String.valueOf(seconds)); Log.d("Game Time", String.valueOf(seconds));
Log.d("total", String.valueOf(totalCorrectResponses)); Log.d("total", String.valueOf(totalCorrectResponses));
...@@ -198,6 +210,8 @@ public class DividedAttentionGame1 extends AppCompatActivity { ...@@ -198,6 +210,8 @@ public class DividedAttentionGame1 extends AppCompatActivity {
case MotionEvent.ACTION_DOWN: { case MotionEvent.ACTION_DOWN: {
red_btn.getBackground().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP); red_btn.getBackground().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
view.invalidate(); view.invalidate();
mp2 = MediaPlayer.create(getApplicationContext(), R.raw.button_click);
mp2.start();
break; break;
} }
case MotionEvent.ACTION_UP: case MotionEvent.ACTION_UP:
...@@ -208,6 +222,7 @@ public class DividedAttentionGame1 extends AppCompatActivity { ...@@ -208,6 +222,7 @@ public class DividedAttentionGame1 extends AppCompatActivity {
totalReactionTime = totalReactionTime + reactionTime; totalReactionTime = totalReactionTime + reactionTime;
Log.d("correct " , startTime + " " + clickedTime + " " + reactionTime); Log.d("correct " , startTime + " " + clickedTime + " " + reactionTime);
noOfCorrectResponses++; noOfCorrectResponses++;
red_btn.setEnabled(false);
} }
else { else {
Log.d( "wrong" , startTime + " " + clickedTime + " " + reactionTime); Log.d( "wrong" , startTime + " " + clickedTime + " " + reactionTime);
......
...@@ -67,9 +67,11 @@ public class FocusedAttentionGame1 extends AppCompatActivity { ...@@ -67,9 +67,11 @@ public class FocusedAttentionGame1 extends AppCompatActivity {
ImageButton red_btn; ImageButton red_btn;
TextView textView; TextView textView;
String clicked = "null";
Integer[] isi = { 3000, 3500, 4000, 4500, 5000, 5500, 6000 }; Integer[] isi = { 3000, 3500, 4000, 4500, 5000, 5500, 6000 };
MediaPlayer mp; MediaPlayer mp, mp2;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -109,6 +111,8 @@ public class FocusedAttentionGame1 extends AppCompatActivity { ...@@ -109,6 +111,8 @@ public class FocusedAttentionGame1 extends AppCompatActivity {
if ( i % 2 != 0 ) { if ( i % 2 != 0 ) {
imageView.setVisibility(View.INVISIBLE); imageView.setVisibility(View.INVISIBLE);
clicked = "null";
red_btn.setEnabled(true);
radomTimer = random.nextInt(5); radomTimer = random.nextInt(5);
updateInterval = isi[radomTimer]; updateInterval = isi[radomTimer];
imageView.postDelayed(this, updateInterval); imageView.postDelayed(this, updateInterval);
...@@ -120,11 +124,13 @@ public class FocusedAttentionGame1 extends AppCompatActivity { ...@@ -120,11 +124,13 @@ public class FocusedAttentionGame1 extends AppCompatActivity {
else { else {
Log.d("***************radomTimer******************", String.valueOf(i + " 1000" )); Log.d("***************radomTimer******************", String.valueOf(i + " 1000" ));
imageView.setVisibility(View.VISIBLE); imageView.setVisibility(View.VISIBLE);
red_btn.setEnabled(true);
imageView.setImageResource(R.drawable.monkey); imageView.setImageResource(R.drawable.monkey);
clicked = "monkey";
startTime = System.currentTimeMillis(); startTime = System.currentTimeMillis();
imageView.postDelayed(this, 1000); imageView.postDelayed(this, 3000);
totalCorrectResponses++; totalCorrectResponses++;
duration = duration + 1000; duration = duration + 3000;
i++; i++;
} }
...@@ -164,19 +170,21 @@ public class FocusedAttentionGame1 extends AppCompatActivity { ...@@ -164,19 +170,21 @@ public class FocusedAttentionGame1 extends AppCompatActivity {
public boolean onTouch(View view, MotionEvent motionEvent) { public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()) { switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN: { case MotionEvent.ACTION_DOWN: {
red_btn.getBackground().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP); red_btn.getBackground().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
view.invalidate(); view.invalidate();
mp2 = MediaPlayer.create(getApplicationContext(), R.raw.button_click);
mp2.start();
break; break;
} }
case MotionEvent.ACTION_UP: case MotionEvent.ACTION_UP:
// Your action here on button click // Your action here on button click
clickedTime = System.currentTimeMillis(); clickedTime = System.currentTimeMillis();
reactionTime = ( clickedTime - startTime ); reactionTime = ( clickedTime - startTime );
if (reactionTime < 4000) { if (clicked.equals("monkey")) {
totalReactionTime = totalReactionTime + reactionTime; totalReactionTime = totalReactionTime + reactionTime;
Log.d("correct " , startTime + " " + clickedTime + " " + reactionTime); Log.d("correct " , startTime + " " + clickedTime + " " + reactionTime);
noOfCorrectResponses++; noOfCorrectResponses++;
red_btn.setEnabled(false);
} }
else { else {
Log.d( "wrong" , startTime + " " + clickedTime + " " + reactionTime); Log.d( "wrong" , startTime + " " + clickedTime + " " + reactionTime);
......
...@@ -17,10 +17,7 @@ import com.anuththara18.attentionassessment.alternating.AlternatingAttentionGame ...@@ -17,10 +17,7 @@ import com.anuththara18.attentionassessment.alternating.AlternatingAttentionGame
import com.anuththara18.attentionassessment.dividedattention.DividedAttentionGame1; import com.anuththara18.attentionassessment.dividedattention.DividedAttentionGame1;
import com.anuththara18.attentionassessment.focused.FocusedAttentionGame1; import com.anuththara18.attentionassessment.focused.FocusedAttentionGame1;
import com.anuththara18.attentionassessment.map.Map2Activity; import com.anuththara18.attentionassessment.map.Map2Activity;
import com.anuththara18.attentionassessment.selective.BirdChoosingActivity; import com.anuththara18.attentionassessment.sustained.BirdChoosingActivity;
import com.anuththara18.attentionassessment.selective.SelectiveAttentionGame1;
import com.anuththara18.attentionassessment.sustained.SustainedAttentionGame1;
import com.anuththara18.attentionassessment.sustained.SustainedAttentionGame2;
@SuppressLint("ValidFragment") @SuppressLint("ValidFragment")
...@@ -46,7 +43,7 @@ public class MainFragment extends Fragment { ...@@ -46,7 +43,7 @@ public class MainFragment extends Fragment {
selectiveAttention = view.findViewById(R.id.selectiveAttention); selectiveAttention = view.findViewById(R.id.selectiveAttention);
dividedAttention = view.findViewById(R.id.dividedAttention); dividedAttention = view.findViewById(R.id.dividedAttention);
sustainedAttention = view.findViewById(R.id.sustainedAttention); sustainedAttention = view.findViewById(R.id.sustainedAttention);
alternatingAttention = view.findViewById(R.id.alternatingAttention); //alternatingAttention = view.findViewById(R.id.alternatingAttention);
alternatingAttention2 = view.findViewById(R.id.alternatingAttention2); alternatingAttention2 = view.findViewById(R.id.alternatingAttention2);
final MediaPlayer mp = MediaPlayer.create(getContext(), R.raw.button1); final MediaPlayer mp = MediaPlayer.create(getContext(), R.raw.button1);
...@@ -87,14 +84,6 @@ public class MainFragment extends Fragment { ...@@ -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() { alternatingAttention2.setOnClickListener(new View.OnClickListener() {
@Override @Override
...@@ -109,6 +98,7 @@ public class MainFragment extends Fragment { ...@@ -109,6 +98,7 @@ public class MainFragment extends Fragment {
} }
} }
/* /*
public class FirstFragment extends Fragment { public class FirstFragment extends Fragment {
......
package com.anuththara18.attentionassessment.home; package com.anuththara18.attentionassessment.home;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.view.GravityCompat; import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout; import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle; import android.os.Bundle;
import android.view.MenuItem; import android.view.MenuItem;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.Toast;
import com.anuththara18.attentionassessment.R; import com.anuththara18.attentionassessment.R;
import com.anuththara18.attentionassessment.consentform.ConsentFormActivity; import com.anuththara18.attentionassessment.consentform.ConsentFormActivity;
import com.google.android.material.navigation.NavigationView; 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{ public class NavigationDrawerActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener{
//FOR DESIGN //FOR DESIGN
...@@ -31,6 +40,9 @@ public class NavigationDrawerActivity extends AppCompatActivity implements Navig ...@@ -31,6 +40,9 @@ public class NavigationDrawerActivity extends AppCompatActivity implements Navig
//FOR DATAS //FOR DATAS
private static final int FRAGMENT_MAINDASHBOARD = 0; private static final int FRAGMENT_MAINDASHBOARD = 0;
// constant code for runtime permissions
private static final int PERMISSION_REQUEST_CODE = 200;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -44,6 +56,14 @@ public class NavigationDrawerActivity extends AppCompatActivity implements Navig ...@@ -44,6 +56,14 @@ public class NavigationDrawerActivity extends AppCompatActivity implements Navig
// Show First Fragment // Show First Fragment
this.showFirstFragment(); this.showFirstFragment();
// below code is used for
// checking our permissions.
if (checkPermission()) {
//Toast.makeText(this, "Permission Granted", Toast.LENGTH_SHORT).show();
} else {
requestPermission();
}
} }
@Override @Override
...@@ -107,6 +127,8 @@ public class NavigationDrawerActivity extends AppCompatActivity implements Navig ...@@ -107,6 +127,8 @@ public class NavigationDrawerActivity extends AppCompatActivity implements Navig
return true; return true;
} }
/**************************************************************************************************/
private void logout() { private void logout() {
//closing activity //closing activity
...@@ -117,9 +139,7 @@ public class NavigationDrawerActivity extends AppCompatActivity implements Navig ...@@ -117,9 +139,7 @@ public class NavigationDrawerActivity extends AppCompatActivity implements Navig
} }
// --------------------- /**************************************************************************************************/
// CONFIGURATION
// ---------------------
// Configure Toolbar // Configure Toolbar
private void configureToolBar(){ private void configureToolBar(){
...@@ -127,6 +147,8 @@ public class NavigationDrawerActivity extends AppCompatActivity implements Navig ...@@ -127,6 +147,8 @@ public class NavigationDrawerActivity extends AppCompatActivity implements Navig
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
} }
/**************************************************************************************************/
//Configure Drawer Layout //Configure Drawer Layout
private void configureDrawerLayout(){ private void configureDrawerLayout(){
this.drawerLayout = (DrawerLayout) findViewById(R.id.activity_main_drawer_layout); this.drawerLayout = (DrawerLayout) findViewById(R.id.activity_main_drawer_layout);
...@@ -135,15 +157,15 @@ public class NavigationDrawerActivity extends AppCompatActivity implements Navig ...@@ -135,15 +157,15 @@ public class NavigationDrawerActivity extends AppCompatActivity implements Navig
toggle.syncState(); toggle.syncState();
} }
/**************************************************************************************************/
//Configure NavigationView //Configure NavigationView
private void configureNavigationView(){ private void configureNavigationView(){
this.navigationView = (NavigationView) findViewById(R.id.activity_main_nav_view); this.navigationView = (NavigationView) findViewById(R.id.activity_main_nav_view);
navigationView.setNavigationItemSelectedListener(this); navigationView.setNavigationItemSelectedListener(this);
} }
// --------------------- /**************************************************************************************************/
// FRAGMENTS
// ---------------------
// Show first fragment when activity is created // Show first fragment when activity is created
private void showFirstFragment(){ private void showFirstFragment(){
...@@ -156,8 +178,9 @@ public class NavigationDrawerActivity extends AppCompatActivity implements Navig ...@@ -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){ private void showFragment(int fragmentIdentifier){
switch (fragmentIdentifier){ switch (fragmentIdentifier){
case FRAGMENT_MAINDASHBOARD : case FRAGMENT_MAINDASHBOARD :
...@@ -180,7 +203,7 @@ public class NavigationDrawerActivity extends AppCompatActivity implements Navig ...@@ -180,7 +203,7 @@ public class NavigationDrawerActivity extends AppCompatActivity implements Navig
} }
} }
// --- /**************************************************************************************************/
// Create each fragment page and show it // Create each fragment page and show it
...@@ -189,8 +212,7 @@ public class NavigationDrawerActivity extends AppCompatActivity implements Navig ...@@ -189,8 +212,7 @@ public class NavigationDrawerActivity extends AppCompatActivity implements Navig
this.startTransactionFragment(this.fragmentMainDashboard); this.startTransactionFragment(this.fragmentMainDashboard);
} }
/**************************************************************************************************/
// ---
// Generic method that will replace and show a fragment inside the MainActivity Frame Layout // Generic method that will replace and show a fragment inside the MainActivity Frame Layout
private void startTransactionFragment(Fragment fragment){ private void startTransactionFragment(Fragment fragment){
...@@ -199,4 +221,54 @@ public class NavigationDrawerActivity extends AppCompatActivity implements Navig ...@@ -199,4 +221,54 @@ public class NavigationDrawerActivity extends AppCompatActivity implements Navig
.replace(R.id.activity_main_frame_layout, fragment).commit(); .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
package com.anuththara18.attentionassessment.selective; package com.anuththara18.attentionassessment.sustained;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView; import androidx.cardview.widget.CardView;
...@@ -9,14 +9,12 @@ import android.os.Bundle; ...@@ -9,14 +9,12 @@ import android.os.Bundle;
import android.view.View; import android.view.View;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.anuththara18.attentionassessment.R; import com.anuththara18.attentionassessment.R;
import com.anuththara18.attentionassessment.language.LanguageSetter; import com.anuththara18.attentionassessment.language.LanguageSetter;
import com.anuththara18.attentionassessment.sustained.SustainedAttentionGame1;
public class BirdChoosingActivity extends AppCompatActivity { public class BirdChoosingActivity extends AppCompatActivity {
...@@ -50,7 +48,7 @@ public class BirdChoosingActivity extends AppCompatActivity { ...@@ -50,7 +48,7 @@ public class BirdChoosingActivity extends AppCompatActivity {
l3 = findViewById(R.id.l3); l3 = findViewById(R.id.l3);
l4 = findViewById(R.id.l4); 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() { bird1.setOnClickListener(new View.OnClickListener() {
@Override @Override
......
...@@ -7,25 +7,19 @@ import android.content.DialogInterface; ...@@ -7,25 +7,19 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.drawable.AnimationDrawable;
import android.media.MediaPlayer; import android.media.MediaPlayer;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.CountDownTimer;
import android.util.Log; import android.util.Log;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.WindowManager; import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.anuththara18.attentionassessment.CompleteScreen2;
import com.anuththara18.attentionassessment.R; import com.anuththara18.attentionassessment.R;
import com.anuththara18.attentionassessment.age.AgeActivity; import com.anuththara18.attentionassessment.age.AgeActivity;
import com.anuththara18.attentionassessment.db.Api; import com.anuththara18.attentionassessment.db.Api;
...@@ -33,14 +27,11 @@ import com.anuththara18.attentionassessment.db.RequestHandler; ...@@ -33,14 +27,11 @@ import com.anuththara18.attentionassessment.db.RequestHandler;
import com.anuththara18.attentionassessment.gender.GenderActivity; import com.anuththara18.attentionassessment.gender.GenderActivity;
import com.anuththara18.attentionassessment.home.NavigationDrawerActivity; import com.anuththara18.attentionassessment.home.NavigationDrawerActivity;
import com.anuththara18.attentionassessment.language.LanguageSetter; import com.anuththara18.attentionassessment.language.LanguageSetter;
import com.anuththara18.attentionassessment.selective.BirdChoosingActivity;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Random; import java.util.Random;
public class SustainedAttentionGame1 extends AppCompatActivity { public class SustainedAttentionGame1 extends AppCompatActivity {
...@@ -57,12 +48,12 @@ public class SustainedAttentionGame1 extends AppCompatActivity { ...@@ -57,12 +48,12 @@ public class SustainedAttentionGame1 extends AppCompatActivity {
// isi = 10 - 60 secs // 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, 45000, 25000, 50000, 20000, 35000, 60000, 15000, 30000, 55000, 40000,
10000, 15000, 10000, 15000 }; 10000, 15000, 10000, 15000 };*/
/*Integer[] isi = { 1000, 4500, 2500, 5000, 2000, 3500, 6000, 1500, 3000, 5500, 4000, 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, 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, Integer[] image = { R.drawable.red_bird_gif,
R.drawable.blue_bird_gif, R.drawable.blue_bird_gif,
...@@ -88,7 +79,7 @@ public class SustainedAttentionGame1 extends AppCompatActivity { ...@@ -88,7 +79,7 @@ public class SustainedAttentionGame1 extends AppCompatActivity {
long totalReactionTime = 0; long totalReactionTime = 0;
int meanReactionTime = 0; int meanReactionTime = 0;
MediaPlayer mp; MediaPlayer mp, mp2;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -134,6 +125,7 @@ public class SustainedAttentionGame1 extends AppCompatActivity { ...@@ -134,6 +125,7 @@ public class SustainedAttentionGame1 extends AppCompatActivity {
randomImage = random.nextInt(6); randomImage = random.nextInt(6);
bird.setVisibility(View.INVISIBLE); bird.setVisibility(View.INVISIBLE);
gifImageView.setVisibility(View.VISIBLE); gifImageView.setVisibility(View.VISIBLE);
red_btn.setEnabled(true);
gifImageView.setImageResource(image[randomImage]); gifImageView.setImageResource(image[randomImage]);
clickedImage = image[randomImage]; clickedImage = image[randomImage];
updateInterval = isi[j]; updateInterval = isi[j];
...@@ -145,7 +137,7 @@ public class SustainedAttentionGame1 extends AppCompatActivity { ...@@ -145,7 +137,7 @@ public class SustainedAttentionGame1 extends AppCompatActivity {
} }
// appearance - 0.5s * 25 times // appearance - 0.5s * 25 times
else if ( totalCorrectResponses <= 25 ) { else if ( totalCorrectResponses <= 25 ) {
Log.d("radomTimer", String.valueOf(i + " 2000" )); Log.d("radomTimer", String.valueOf(i + " 3000" ));
Log.d("******************************", "start 1"); Log.d("******************************", "start 1");
if (BirdChoosingActivity.birdSelected == 1) { if (BirdChoosingActivity.birdSelected == 1) {
...@@ -167,11 +159,12 @@ public class SustainedAttentionGame1 extends AppCompatActivity { ...@@ -167,11 +159,12 @@ public class SustainedAttentionGame1 extends AppCompatActivity {
} }
bird.setVisibility(View.VISIBLE); bird.setVisibility(View.VISIBLE);
red_btn.setEnabled(true);
gifImageView.setVisibility(View.INVISIBLE); gifImageView.setVisibility(View.INVISIBLE);
startTime = System.currentTimeMillis(); startTime = System.currentTimeMillis();
gifImageView.postDelayed(this, 2000); gifImageView.postDelayed(this, 3000);
totalCorrectResponses++; totalCorrectResponses++;
duration = duration + 2000; duration = duration + 3000;
i++; i++;
} }
...@@ -219,15 +212,13 @@ public class SustainedAttentionGame1 extends AppCompatActivity { ...@@ -219,15 +212,13 @@ public class SustainedAttentionGame1 extends AppCompatActivity {
public void onClick(View view) { public void onClick(View view) {
clickedTime = System.currentTimeMillis(); clickedTime = System.currentTimeMillis();
reactionTime = ( clickedTime - startTime ); reactionTime = ( clickedTime - startTime );
mp2 = MediaPlayer.create(getApplicationContext(), R.raw.button_click);
mp2.start();
if (correctImage == clickedImage) { if (correctImage == clickedImage) {
totalReactionTime = (long) (totalReactionTime + reactionTime); totalReactionTime = (long) (totalReactionTime + reactionTime);
Log.d("correct " , startTime + " " + clickedTime + " " + reactionTime); Log.d("correct " , startTime + " " + clickedTime + " " + reactionTime);
noOfCorrectResponses++; noOfCorrectResponses++;
} red_btn.setEnabled(false);
else if (reactionTime < 4000) {
totalReactionTime = (long) (totalReactionTime + reactionTime);
Log.d("correct " , startTime + " " + clickedTime + " " + reactionTime);
noOfCorrectResponses++;
} }
else { else {
noOfCommissionErrors++; noOfCommissionErrors++;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@drawable/bg5" android:background="@drawable/bg5"
tools:context=".selective.BirdChoosingActivity"> tools:context=".sustained.BirdChoosingActivity">
<ImageButton <ImageButton
android:id="@+id/cross_btn" android:id="@+id/cross_btn"
......
...@@ -221,7 +221,7 @@ ...@@ -221,7 +221,7 @@
android:textSize="20dp" android:textSize="20dp"
android:layout_marginRight="15dp" android:layout_marginRight="15dp"
android:fontFamily="@font/aclonica" android:fontFamily="@font/aclonica"
android:text="Sustained Attention I" android:text="Sustained Attention"
android:textStyle="bold"/> android:textStyle="bold"/>
<ImageView <ImageView
...@@ -235,6 +235,8 @@ ...@@ -235,6 +235,8 @@
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>
<!--
<androidx.cardview.widget.CardView <androidx.cardview.widget.CardView
android:id="@+id/alternatingAttention" android:id="@+id/alternatingAttention"
android:layout_height="200dp" android:layout_height="200dp"
...@@ -290,6 +292,8 @@ ...@@ -290,6 +292,8 @@
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>
-->
<androidx.cardview.widget.CardView <androidx.cardview.widget.CardView
android:id="@+id/alternatingAttention2" android:id="@+id/alternatingAttention2"
android:layout_height="200dp" 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