Commit 71fe4d66 authored by Anuththara18's avatar Anuththara18

Handling Back Pressed Events

parent 1835a808
package com.anuththara18.attentionassessment.age; package com.anuththara18.attentionassessment.age;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintLayout;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
...@@ -359,6 +361,38 @@ public class AgeActivity extends AppCompatActivity { ...@@ -359,6 +361,38 @@ public class AgeActivity extends AppCompatActivity {
/*************************************************************************************************/ /*************************************************************************************************/
@Override
public void onBackPressed() {
super.onBackPressed();
alert();
}
/*************************************************************************************************/
private void alert() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setMessage("Do you really want to quit the game?");
alertDialogBuilder.setPositiveButton("yes",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
finish();
}
});
alertDialogBuilder.setNegativeButton("No",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//finish();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
/*************************************************************************************************/
public void getDimensions() { public void getDimensions() {
if ( count == 1 ) { if ( count == 1 ) {
leftFromXDelta = 0; leftFromXDelta = 0;
......
package com.anuththara18.attentionassessment.consentform; package com.anuththara18.attentionassessment.consentform;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
...@@ -12,6 +13,7 @@ import android.widget.Button; ...@@ -12,6 +13,7 @@ import android.widget.Button;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.TextView; import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
...@@ -112,4 +114,36 @@ public class ConsentFormActivity extends AppCompatActivity { ...@@ -112,4 +114,36 @@ public class ConsentFormActivity extends AppCompatActivity {
consentFormList.add(new ConsentForm("Whom do I call if I have questions or problems?", "If you have any questions regarding your rights as a participant in this research and/or concerns about the study, or if you feel under any pressure to enroll or to continue to participate in this study, you may contact the Dr Pradeepa Samarasinghe, Principle Investigator at Sri Lanka Institute of Information Technology at 0723537952 or pradeepa.s@sliit.lk .")); consentFormList.add(new ConsentForm("Whom do I call if I have questions or problems?", "If you have any questions regarding your rights as a participant in this research and/or concerns about the study, or if you feel under any pressure to enroll or to continue to participate in this study, you may contact the Dr Pradeepa Samarasinghe, Principle Investigator at Sri Lanka Institute of Information Technology at 0723537952 or pradeepa.s@sliit.lk ."));
} }
/*************************************************************************************************/
@Override
public void onBackPressed() {
super.onBackPressed();
alert();
}
/*************************************************************************************************/
private void alert() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setMessage("Do you really want to quit the game?");
alertDialogBuilder.setPositiveButton("yes",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
finish();
}
});
alertDialogBuilder.setNegativeButton("No",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//finish();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
} }
\ No newline at end of file
...@@ -162,6 +162,7 @@ public class GetParentsConsentActivity extends AppCompatActivity { ...@@ -162,6 +162,7 @@ public class GetParentsConsentActivity extends AppCompatActivity {
ed.apply(); ed.apply();
//Toast.makeText(getApplicationContext(), String.valueOf(imageSet), Toast.LENGTH_LONG).show(); //Toast.makeText(getApplicationContext(), String.valueOf(imageSet), Toast.LENGTH_LONG).show();
//Toast.makeText(getApplicationContext(), "Consent Saved Successfully!", Toast.LENGTH_SHORT).show(); //Toast.makeText(getApplicationContext(), "Consent Saved Successfully!", Toast.LENGTH_SHORT).show();
finish();
Intent intent = new Intent(getApplicationContext(), NavigationDrawerActivity.class); Intent intent = new Intent(getApplicationContext(), NavigationDrawerActivity.class);
startActivity(intent); startActivity(intent);
} }
......
package com.anuththara18.attentionassessment.consentform; package com.anuththara18.attentionassessment.consentform;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
...@@ -21,6 +22,7 @@ import android.widget.Button; ...@@ -21,6 +22,7 @@ import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.Toast; import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import com.anuththara18.attentionassessment.R; import com.anuththara18.attentionassessment.R;
...@@ -238,4 +240,36 @@ public class GetSignatureActivity extends AppCompatActivity { ...@@ -238,4 +240,36 @@ public class GetSignatureActivity extends AppCompatActivity {
dirtyRect.bottom = Math.max(lastTouchY, eventY); dirtyRect.bottom = Math.max(lastTouchY, eventY);
} }
} }
/*************************************************************************************************/
@Override
public void onBackPressed() {
super.onBackPressed();
alert();
}
/*************************************************************************************************/
private void alert() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setMessage("Do you really want to quit the game?");
alertDialogBuilder.setPositiveButton("yes",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
finish();
}
});
alertDialogBuilder.setNegativeButton("No",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//finish();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
} }
\ No newline at end of file
package com.anuththara18.attentionassessment.consentform; package com.anuththara18.attentionassessment.consentform;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
...@@ -11,6 +12,7 @@ import android.view.animation.AnimationUtils; ...@@ -11,6 +12,7 @@ import android.view.animation.AnimationUtils;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.TextView; import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
...@@ -101,4 +103,35 @@ public class SinhalaConsentFormActivity extends AppCompatActivity { ...@@ -101,4 +103,35 @@ public class SinhalaConsentFormActivity extends AppCompatActivity {
consentFormList.add(new ConsentForm("ඔබට යම් ප්\u200Dරශ්නයක් හෝ ගැටළුවක් ඇත්නම් දුරකථනයෙන් සම්බන්ධ කරගත හැකි අය ", "මෙම පර්යේෂණය සඳහා සහභාගී වීමේදී ඔබේ අයිතිවාසිකම් පිළිබඳව හෝ පර්යේෂණය හා සම්බන්ධ කිසියම් කාරණයක් දැනගැනීමට අවශ්\u200Dය නම් සහ මෙම පර්යේෂණය සමග සම්බන්ධ වීමට හෝ තවදුරටත් කරගෙන යාමට ඔබට යම් අපහසුතාවයක් ඇත්නම් 0723537952 දුරකථන අංකයෙන් හෝ pradeepa.s@sliit.lk විද්\u200Dයුත් තැපැල් ලිපිනයෙන්, ශ්\u200Dරී ලංකා තොරතුරු තාක්ෂණ ආයතනයේ ප්\u200Dරධාන පර්යේෂිකා (principal investigator) ආචාර්ය ප්\u200Dරදීපා සමරසිංහ මහත්මිය සම්බන්ධ කරගැනීමට හැකියාව ඇත. ")); consentFormList.add(new ConsentForm("ඔබට යම් ප්\u200Dරශ්නයක් හෝ ගැටළුවක් ඇත්නම් දුරකථනයෙන් සම්බන්ධ කරගත හැකි අය ", "මෙම පර්යේෂණය සඳහා සහභාගී වීමේදී ඔබේ අයිතිවාසිකම් පිළිබඳව හෝ පර්යේෂණය හා සම්බන්ධ කිසියම් කාරණයක් දැනගැනීමට අවශ්\u200Dය නම් සහ මෙම පර්යේෂණය සමග සම්බන්ධ වීමට හෝ තවදුරටත් කරගෙන යාමට ඔබට යම් අපහසුතාවයක් ඇත්නම් 0723537952 දුරකථන අංකයෙන් හෝ pradeepa.s@sliit.lk විද්\u200Dයුත් තැපැල් ලිපිනයෙන්, ශ්\u200Dරී ලංකා තොරතුරු තාක්ෂණ ආයතනයේ ප්\u200Dරධාන පර්යේෂිකා (principal investigator) ආචාර්ය ප්\u200Dරදීපා සමරසිංහ මහත්මිය සම්බන්ධ කරගැනීමට හැකියාව ඇත. "));
} }
/*************************************************************************************************/
@Override
public void onBackPressed() {
super.onBackPressed();
alert();
}
/*************************************************************************************************/
private void alert() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setMessage("Do you really want to quit the game?");
alertDialogBuilder.setPositiveButton("yes",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
finish();
}
});
alertDialogBuilder.setNegativeButton("No",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//finish();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
} }
\ No newline at end of file
package com.anuththara18.attentionassessment.details; package com.anuththara18.attentionassessment.details;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
...@@ -150,4 +152,36 @@ public class ParentDetailsActivity extends AppCompatActivity { ...@@ -150,4 +152,36 @@ public class ParentDetailsActivity extends AppCompatActivity {
return TextUtils.isEmpty(phone) || (m.find() && m.group().equals(phone)); return TextUtils.isEmpty(phone) || (m.find() && m.group().equals(phone));
} }
/*************************************************************************************************/
@Override
public void onBackPressed() {
super.onBackPressed();
alert();
}
/*************************************************************************************************/
private void alert() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setMessage("Do you really want to quit the game?");
alertDialogBuilder.setPositiveButton("yes",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
finish();
}
});
alertDialogBuilder.setNegativeButton("No",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//finish();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
} }
\ No newline at end of file
package com.anuththara18.attentionassessment.gender; package com.anuththara18.attentionassessment.gender;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.media.MediaPlayer; import android.media.MediaPlayer;
import android.os.Build; import android.os.Build;
...@@ -22,6 +24,7 @@ import android.widget.Toast; ...@@ -22,6 +24,7 @@ import android.widget.Toast;
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.details.ParentDetailsActivity; import com.anuththara18.attentionassessment.details.ParentDetailsActivity;
import com.anuththara18.attentionassessment.home.NavigationDrawerActivity;
import com.anuththara18.attentionassessment.language.LanguageActivity; import com.anuththara18.attentionassessment.language.LanguageActivity;
import com.anuththara18.attentionassessment.language.LanguageSetter; import com.anuththara18.attentionassessment.language.LanguageSetter;
...@@ -202,4 +205,37 @@ public class GenderActivity extends AppCompatActivity { ...@@ -202,4 +205,37 @@ public class GenderActivity extends AppCompatActivity {
}); });
} }
/*************************************************************************************************/
@Override
public void onBackPressed() {
super.onBackPressed();
alert();
}
/*************************************************************************************************/
private void alert() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setMessage("Do you really want to quit the game?");
alertDialogBuilder.setPositiveButton("yes",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
finish();
}
});
alertDialogBuilder.setNegativeButton("No",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//finish();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
} }
\ No newline at end of file
package com.anuththara18.attentionassessment.home; package com.anuththara18.attentionassessment.home;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.media.MediaPlayer; import android.media.MediaPlayer;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Toast;
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.cardview.widget.CardView; import androidx.cardview.widget.CardView;
import androidx.drawerlayout.widget.DrawerLayout; import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
...@@ -109,6 +113,54 @@ public class MainFragment extends Fragment { ...@@ -109,6 +113,54 @@ public class MainFragment extends Fragment {
} }
/*************************************************************************************************/
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// This callback will only be called when MyFragment is at least Started.
OnBackPressedCallback callback = new OnBackPressedCallback(true /* enabled by default */) {
@Override
public void handleOnBackPressed() {
//Toast.makeText(getContext(), "predescnjdfcfd", Toast.LENGTH_SHORT).show();
alert();
}
};
requireActivity().getOnBackPressedDispatcher().addCallback(this, callback);
// The callback can be enabled or disabled here or in handleOnBackPressed()
}
/*************************************************************************************************/
private void alert() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getContext());
alertDialogBuilder.setMessage("Do you really want to quit the game?");
alertDialogBuilder.setPositiveButton("yes",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
getActivity().finish();
}
});
alertDialogBuilder.setNegativeButton("No",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//finish();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
/*************************************************************************************************/
} }
/* /*
public class FirstFragment extends Fragment { public class FirstFragment extends Fragment {
......
package com.anuththara18.attentionassessment.language; package com.anuththara18.attentionassessment.language;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Resources; import android.content.res.Resources;
...@@ -24,6 +26,7 @@ import android.widget.Toast; ...@@ -24,6 +26,7 @@ import android.widget.Toast;
import com.anuththara18.attentionassessment.R; import com.anuththara18.attentionassessment.R;
import com.anuththara18.attentionassessment.details.ParentDetailsActivity; import com.anuththara18.attentionassessment.details.ParentDetailsActivity;
import com.anuththara18.attentionassessment.gender.GenderActivity; import com.anuththara18.attentionassessment.gender.GenderActivity;
import com.anuththara18.attentionassessment.home.NavigationDrawerActivity;
import com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult; import com.google.firebase.auth.AuthResult;
...@@ -244,6 +247,40 @@ public class LanguageActivity extends AppCompatActivity { ...@@ -244,6 +247,40 @@ public class LanguageActivity extends AppCompatActivity {
}); });
} }
/*************************************************************************************************/
@Override
public void onBackPressed() {
super.onBackPressed();
alert();
}
private void alert() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setMessage("Do you really want to quit the game?");
alertDialogBuilder.setPositiveButton("yes",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
finish();
}
});
alertDialogBuilder.setNegativeButton("No",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//finish();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
/*************************************************************************************************/
public void englishSelected() { public void englishSelected() {
english_btn.getLayoutParams().height = 700; english_btn.getLayoutParams().height = 700;
english_btn.getLayoutParams().width= 700; english_btn.getLayoutParams().width= 700;
......
...@@ -70,16 +70,20 @@ public class IntroductoryVideoLandscapeActivity extends AppCompatActivity { ...@@ -70,16 +70,20 @@ public class IntroductoryVideoLandscapeActivity extends AppCompatActivity {
public void onClick(View view) { public void onClick(View view) {
if (MainFragment.game.equals("focused")) { if (MainFragment.game.equals("focused")) {
if (Map1Activity.level == 1){ if (Map1Activity.level == 1){
finish();
startActivity(new Intent(getApplicationContext(), FocusedAttentionGame2.class)); startActivity(new Intent(getApplicationContext(), FocusedAttentionGame2.class));
} }
else if (Map1Activity.level == 2){ else if (Map1Activity.level == 2){
finish();
startActivity(new Intent(getApplicationContext(), FocusedAttentionGame2.class)); startActivity(new Intent(getApplicationContext(), FocusedAttentionGame2.class));
} }
else if (Map1Activity.level == 5){ else if (Map1Activity.level == 5){
finish();
startActivity(new Intent(getApplicationContext(), FocusedAttentionGame1.class)); startActivity(new Intent(getApplicationContext(), FocusedAttentionGame1.class));
} }
} }
else if (MainFragment.game.equals("alternating")) { else if (MainFragment.game.equals("alternating")) {
finish();
startActivity(new Intent(getApplicationContext(), AlternatingAttentionGame1.class)); startActivity(new Intent(getApplicationContext(), AlternatingAttentionGame1.class));
} }
} }
......
...@@ -63,19 +63,24 @@ public class IntroductoryVideoPortraitActivity extends AppCompatActivity { ...@@ -63,19 +63,24 @@ public class IntroductoryVideoPortraitActivity extends AppCompatActivity {
public void onClick(View view) { public void onClick(View view) {
if (MainFragment.game.equals("focused")) { if (MainFragment.game.equals("focused")) {
if (Map1Activity.level == 3){ if (Map1Activity.level == 3){
finish();
startActivity(new Intent(getApplicationContext(), AnimalChoosingActivity.class)); startActivity(new Intent(getApplicationContext(), AnimalChoosingActivity.class));
} }
else if (Map1Activity.level == 4){ else if (Map1Activity.level == 4){
finish();
startActivity(new Intent(getApplicationContext(), AnimalChoosingActivity.class)); startActivity(new Intent(getApplicationContext(), AnimalChoosingActivity.class));
} }
} }
else if (MainFragment.game.equals("divided")) { else if (MainFragment.game.equals("divided")) {
finish();
startActivity(new Intent(getApplicationContext(), DividedAttentionGame1.class)); startActivity(new Intent(getApplicationContext(), DividedAttentionGame1.class));
} }
else if (MainFragment.game.equals("selective")) { else if (MainFragment.game.equals("selective")) {
finish();
startActivity(new Intent(getApplicationContext(), SelectiveAttentionGame1.class)); startActivity(new Intent(getApplicationContext(), SelectiveAttentionGame1.class));
} }
else if (MainFragment.game.equals("sustained")) { else if (MainFragment.game.equals("sustained")) {
finish();
startActivity(new Intent(getApplicationContext(), BirdChoosingActivity.class)); startActivity(new Intent(getApplicationContext(), BirdChoosingActivity.class));
} }
} }
......
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