Commit 56117cd3 authored by Anuththara18's avatar Anuththara18

Added Shared Preferences for Language Selection & Removed Unwanted Toasts

parent 6511a378
...@@ -4,6 +4,7 @@ import androidx.appcompat.app.AppCompatActivity; ...@@ -4,6 +4,7 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintLayout;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build; import android.os.Build;
...@@ -44,7 +45,8 @@ public class AgeActivity extends AppCompatActivity { ...@@ -44,7 +45,8 @@ public class AgeActivity extends AppCompatActivity {
ImageView bunny_img; ImageView bunny_img;
TextView age_txt, next, previous, selectAge; TextView age_txt, next, previous, selectAge;
public static int age = 4; public static int age = 4;
SharedPreferences sharedPreferences;
int imageCheck;
int width; int width;
int count; int count;
float rightFromXDelta, rightToXDelta, leftFromXDelta, leftToXDelta; float rightFromXDelta, rightToXDelta, leftFromXDelta, leftToXDelta;
...@@ -74,6 +76,8 @@ public class AgeActivity extends AppCompatActivity { ...@@ -74,6 +76,8 @@ public class AgeActivity extends AppCompatActivity {
next = (TextView)findViewById(R.id.next); next = (TextView)findViewById(R.id.next);
previous = (TextView)findViewById(R.id.previous); previous = (TextView)findViewById(R.id.previous);
selectAge = (TextView)findViewById(R.id.selectAge); selectAge = (TextView)findViewById(R.id.selectAge);
sharedPreferences = getSharedPreferences("ImageCheck", MODE_PRIVATE);
imageCheck = sharedPreferences.getInt("ImageSet", 5);
mDatabase = openOrCreateDatabase(DATABASE_NAME, MODE_PRIVATE, null); mDatabase = openOrCreateDatabase(DATABASE_NAME, MODE_PRIVATE, null);
...@@ -129,13 +133,23 @@ public class AgeActivity extends AppCompatActivity { ...@@ -129,13 +133,23 @@ public class AgeActivity extends AppCompatActivity {
//saveDataToOnlineDB(); //saveDataToOnlineDB();
createTable(); createTable();
saveDataToLocalDB(); saveDataToLocalDB();
if ( LanguageActivity.text.equals("English")) {
if (LanguageActivity.text.equals("English")) {
startActivity(new Intent(AgeActivity.this, ConsentFormActivity.class)); startActivity(new Intent(AgeActivity.this, ConsentFormActivity.class));
} } else {
else {
startActivity(new Intent(AgeActivity.this, SinhalaConsentFormActivity.class)); startActivity(new Intent(AgeActivity.this, SinhalaConsentFormActivity.class));
} }
/*if(imageCheck==1) {
Intent navInt = new Intent(getApplicationContext(), NavigationDrawerActivity.class);
startActivity(navInt);
}
else{
}
*/
//startActivity(new Intent(AgeActivity.this, NavigationDrawerActivity.class)); //startActivity(new Intent(AgeActivity.this, NavigationDrawerActivity.class));
} }
}); });
...@@ -338,7 +352,7 @@ public class AgeActivity extends AppCompatActivity { ...@@ -338,7 +352,7 @@ public class AgeActivity extends AppCompatActivity {
mDatabase.execSQL(insertSQL, new String[]{gender, age, name, email, contact}); mDatabase.execSQL(insertSQL, new String[]{gender, age, name, email, contact});
Toast.makeText(this, "Data Added Successfully", Toast.LENGTH_SHORT).show(); //Toast.makeText(this, "Data Added Successfully", Toast.LENGTH_SHORT).show();
} }
/*************************************************************************************************/ /*************************************************************************************************/
......
...@@ -337,7 +337,7 @@ public class AACompleteScreen extends AppCompatActivity { ...@@ -337,7 +337,7 @@ public class AACompleteScreen extends AppCompatActivity {
// below line is to print toast message // below line is to print toast message
// on completion of PDF generation. // on completion of PDF generation.
Toast.makeText(getApplicationContext(), "PDF file generated successfully.", Toast.LENGTH_LONG).show(); //Toast.makeText(getApplicationContext(), "PDF file generated successfully.", Toast.LENGTH_LONG).show();
} catch (IOException e) { } catch (IOException e) {
// below line is used // below line is used
......
...@@ -475,7 +475,7 @@ public class AlternatingAttentionGame1 extends AppCompatActivity { ...@@ -475,7 +475,7 @@ public class AlternatingAttentionGame1 extends AppCompatActivity {
mDatabase.execSQL(insertSQL, new Integer[]{child_ID, total_correct_responses, no_of_correct_responses, no_of_commission_errors, no_of_ommission_errors, mean_reaction_time, total_duration}); mDatabase.execSQL(insertSQL, new Integer[]{child_ID, total_correct_responses, no_of_correct_responses, no_of_commission_errors, no_of_ommission_errors, mean_reaction_time, total_duration});
Toast.makeText(this, "Data Added Successfully", Toast.LENGTH_SHORT).show(); //Toast.makeText(this, "Data Added Successfully", Toast.LENGTH_SHORT).show();
} }
/*************************************************************************************************/ /*************************************************************************************************/
......
...@@ -4,6 +4,7 @@ import android.Manifest; ...@@ -4,6 +4,7 @@ import android.Manifest;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
...@@ -45,6 +46,8 @@ public class GetParentsConsentActivity extends AppCompatActivity { ...@@ -45,6 +46,8 @@ public class GetParentsConsentActivity extends AppCompatActivity {
Button btnGetSignature; Button btnGetSignature;
public static ImageView fingerprintImageView; public static ImageView fingerprintImageView;
static int flag2 = 0; static int flag2 = 0;
public SharedPreferences sharedPreferences;
public int imageSet = 0;
// constant code for runtime permissions // constant code for runtime permissions
private static final int PERMISSION_REQUEST_CODE = 200; private static final int PERMISSION_REQUEST_CODE = 200;
...@@ -68,6 +71,7 @@ public class GetParentsConsentActivity extends AppCompatActivity { ...@@ -68,6 +71,7 @@ public class GetParentsConsentActivity extends AppCompatActivity {
next = (TextView) findViewById(R.id.next); next = (TextView) findViewById(R.id.next);
btnGetSignature = (Button)findViewById(R.id.btnGetSignature); btnGetSignature = (Button)findViewById(R.id.btnGetSignature);
fingerprintImageView = (ImageView)findViewById(R.id.fingerprintImageView); fingerprintImageView = (ImageView)findViewById(R.id.fingerprintImageView);
sharedPreferences = getSharedPreferences("ImageSet", MODE_PRIVATE);
textView3.setText(LanguageSetter.getresources().getString(R.string.provideconsent)); textView3.setText(LanguageSetter.getresources().getString(R.string.provideconsent));
next.setText(LanguageSetter.getresources().getString(R.string.proceed)); next.setText(LanguageSetter.getresources().getString(R.string.proceed));
...@@ -127,13 +131,17 @@ public class GetParentsConsentActivity extends AppCompatActivity { ...@@ -127,13 +131,17 @@ public class GetParentsConsentActivity extends AppCompatActivity {
try{ try{
sqLiteHelper.insertData(imageViewToByte(fingerprintImageView)); sqLiteHelper.insertData(imageViewToByte(fingerprintImageView));
Toast.makeText(getApplicationContext(), "Consent Saved Successfully!", Toast.LENGTH_SHORT).show(); imageSet = 1;
SharedPreferences.Editor ed = sharedPreferences.edit();
ed.putInt("ImageSet", imageSet);
ed.apply();
//Toast.makeText(getApplicationContext(), String.valueOf(imageSet), Toast.LENGTH_LONG).show();
//Toast.makeText(getApplicationContext(), "Consent Saved Successfully!", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getApplicationContext(), NavigationDrawerActivity.class); Intent intent = new Intent(getApplicationContext(), NavigationDrawerActivity.class);
startActivity(intent); startActivity(intent);
} }
catch (Exception e){ catch (Exception e){
Toast.makeText(getApplicationContext(), "Consent not Saved!", Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), "Consent not Saved!", Toast.LENGTH_SHORT).show();
e.printStackTrace(); e.printStackTrace();
} }
...@@ -190,6 +198,13 @@ public class GetParentsConsentActivity extends AppCompatActivity { ...@@ -190,6 +198,13 @@ public class GetParentsConsentActivity extends AppCompatActivity {
//Toast.makeText(this, "Permission Granted..", Toast.LENGTH_SHORT).show(); //Toast.makeText(this, "Permission Granted..", Toast.LENGTH_SHORT).show();
} else { } else {
Toast.makeText(this, "Permission Denined.", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "Permission Denined.", Toast.LENGTH_SHORT).show();
requestPermission();
/*
if ( !checkPermission() ) {
Toast.makeText(this, "No Use.", Toast.LENGTH_SHORT).show();
System.exit(0);
}
*/
finish(); finish();
} }
} }
......
...@@ -90,7 +90,7 @@ public class GetSignatureActivity extends AppCompatActivity { ...@@ -90,7 +90,7 @@ public class GetSignatureActivity extends AppCompatActivity {
GetParentsConsentActivity.fingerprintImageView.setImageBitmap(bitmap); GetParentsConsentActivity.fingerprintImageView.setImageBitmap(bitmap);
GetParentsConsentActivity.flag2 = 1; GetParentsConsentActivity.flag2 = 1;
Toast.makeText(getApplicationContext(), "Signature Recorded", Toast.LENGTH_SHORT).show(); //Toast.makeText(getApplicationContext(), "Signature Recorded", Toast.LENGTH_SHORT).show();
finish(); finish();
} }
......
...@@ -340,7 +340,7 @@ public class DACompleteScreen extends AppCompatActivity { ...@@ -340,7 +340,7 @@ public class DACompleteScreen extends AppCompatActivity {
// below line is to print toast message // below line is to print toast message
// on completion of PDF generation. // on completion of PDF generation.
Toast.makeText(getApplicationContext(), "PDF file generated successfully.", Toast.LENGTH_LONG).show(); //Toast.makeText(getApplicationContext(), "PDF file generated successfully.", Toast.LENGTH_LONG).show();
} catch (IOException e) { } catch (IOException e) {
// below line is used // below line is used
......
...@@ -583,7 +583,7 @@ public class DividedAttentionGame1 extends AppCompatActivity { ...@@ -583,7 +583,7 @@ public class DividedAttentionGame1 extends AppCompatActivity {
mDatabase.execSQL(insertSQL, new Integer[]{child_ID, total_correct_responses, no_of_correct_responses, no_of_commission_errors, no_of_ommission_errors, mean_reaction_time, total_duration}); mDatabase.execSQL(insertSQL, new Integer[]{child_ID, total_correct_responses, no_of_correct_responses, no_of_commission_errors, no_of_ommission_errors, mean_reaction_time, total_duration});
Toast.makeText(this, "Data Added Successfully", Toast.LENGTH_SHORT).show(); //Toast.makeText(this, "Data Added Successfully", Toast.LENGTH_SHORT).show();
} }
/*************************************************************************************************/ /*************************************************************************************************/
......
...@@ -323,7 +323,7 @@ public class FACompleteScreen extends AppCompatActivity { ...@@ -323,7 +323,7 @@ public class FACompleteScreen extends AppCompatActivity {
// below line is to print toast message // below line is to print toast message
// on completion of PDF generation. // on completion of PDF generation.
Toast.makeText(getApplicationContext(), "PDF file generated successfully.", Toast.LENGTH_LONG).show(); //Toast.makeText(getApplicationContext(), "PDF file generated successfully.", Toast.LENGTH_LONG).show();
} catch (IOException e) { } catch (IOException e) {
// below line is used // below line is used
......
...@@ -507,7 +507,7 @@ public class FocusedAttentionGame1 extends AppCompatActivity { ...@@ -507,7 +507,7 @@ public class FocusedAttentionGame1 extends AppCompatActivity {
mDatabase.execSQL(insertSQL, new Integer[]{child_ID, total_correct_responses, no_of_correct_responses, no_of_commission_errors, no_of_ommission_errors, mean_reaction_time, total_duration}); mDatabase.execSQL(insertSQL, new Integer[]{child_ID, total_correct_responses, no_of_correct_responses, no_of_commission_errors, no_of_ommission_errors, mean_reaction_time, total_duration});
Toast.makeText(this, "Data Added Successfully", Toast.LENGTH_SHORT).show(); //Toast.makeText(this, "Data Added Successfully", Toast.LENGTH_SHORT).show();
} }
/*************************************************************************************************/ /*************************************************************************************************/
......
...@@ -3,6 +3,7 @@ package com.anuththara18.attentionassessment.language; ...@@ -3,6 +3,7 @@ package com.anuththara18.attentionassessment.language;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
...@@ -21,8 +22,10 @@ public class LanguageActivity extends AppCompatActivity { ...@@ -21,8 +22,10 @@ public class LanguageActivity extends AppCompatActivity {
ImageButton english_btn, sinhala_btn, sinhala_txt_btn; ImageButton english_btn, sinhala_btn, sinhala_txt_btn;
TextView english_txt; TextView english_txt;
public static String text = null; public static String text = "";
public static final String sharedKey = "Language";
TextView selectLanguage, next; TextView selectLanguage, next;
public static SharedPreferences sharedPref;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -42,6 +45,7 @@ public class LanguageActivity extends AppCompatActivity { ...@@ -42,6 +45,7 @@ public class LanguageActivity extends AppCompatActivity {
english_txt = (TextView) findViewById(R.id.english_txt); english_txt = (TextView) findViewById(R.id.english_txt);
selectLanguage = (TextView) findViewById(R.id.selectLanguage); selectLanguage = (TextView) findViewById(R.id.selectLanguage);
next = (TextView) findViewById(R.id.next); next = (TextView) findViewById(R.id.next);
sharedPref = getSharedPreferences(sharedKey, MODE_PRIVATE);
english_btn.setOnClickListener(new View.OnClickListener() { english_btn.setOnClickListener(new View.OnClickListener() {
@Override @Override
...@@ -74,7 +78,7 @@ public class LanguageActivity extends AppCompatActivity { ...@@ -74,7 +78,7 @@ public class LanguageActivity extends AppCompatActivity {
next.setOnClickListener(new View.OnClickListener() { next.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if ( text == null ) { if ( text.isEmpty() ) {
Toast.makeText(getApplicationContext(), "Please select a language", Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), "Please select a language", Toast.LENGTH_SHORT).show();
} }
else { else {
...@@ -98,6 +102,7 @@ public class LanguageActivity extends AppCompatActivity { ...@@ -98,6 +102,7 @@ public class LanguageActivity extends AppCompatActivity {
sinhala_txt_btn.getLayoutParams().width= 394; sinhala_txt_btn.getLayoutParams().width= 394;
sinhala_txt_btn.requestLayout(); sinhala_txt_btn.requestLayout();
text = "English"; text = "English";
setLangPref();
changeLanguage(); changeLanguage();
} }
...@@ -114,6 +119,7 @@ public class LanguageActivity extends AppCompatActivity { ...@@ -114,6 +119,7 @@ public class LanguageActivity extends AppCompatActivity {
sinhala_txt_btn.getLayoutParams().width= 410; sinhala_txt_btn.getLayoutParams().width= 410;
sinhala_txt_btn.requestLayout(); sinhala_txt_btn.requestLayout();
text = "සිංහල"; text = "සිංහල";
setLangPref();
changeLanguage(); changeLanguage();
} }
...@@ -122,7 +128,11 @@ public class LanguageActivity extends AppCompatActivity { ...@@ -122,7 +128,11 @@ public class LanguageActivity extends AppCompatActivity {
LanguageSetter.changeLanguage(text, LanguageActivity.this); LanguageSetter.changeLanguage(text, LanguageActivity.this);
next.setText(LanguageSetter.getresources().getString(R.string.next)); next.setText(LanguageSetter.getresources().getString(R.string.next));
selectLanguage.setText(LanguageSetter.getresources().getString(R.string.language)); selectLanguage.setText(LanguageSetter.getresources().getString(R.string.language));
} }
public void setLangPref() {
SharedPreferences.Editor edit = sharedPref.edit();
edit.putString("Lang", text);
edit.apply();
}
} }
\ No newline at end of file
...@@ -274,7 +274,7 @@ public class SelectiveACompleteScreen extends AppCompatActivity { ...@@ -274,7 +274,7 @@ public class SelectiveACompleteScreen extends AppCompatActivity {
try { try {
pdfDocument.writeTo(new FileOutputStream(file)); pdfDocument.writeTo(new FileOutputStream(file));
Toast.makeText(getApplicationContext(), "PDF file generated successfully.", Toast.LENGTH_LONG).show(); //Toast.makeText(getApplicationContext(), "PDF file generated successfully.", Toast.LENGTH_LONG).show();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
......
...@@ -815,7 +815,7 @@ public class SelectiveAttentionGame1 extends AppCompatActivity { ...@@ -815,7 +815,7 @@ public class SelectiveAttentionGame1 extends AppCompatActivity {
mDatabase.execSQL(insertSQL, new Integer[]{child_ID, total_correct_responses, no_of_correct_responses, no_of_commission_errors, no_of_ommission_errors, mean_reaction_time, total_duration}); mDatabase.execSQL(insertSQL, new Integer[]{child_ID, total_correct_responses, no_of_correct_responses, no_of_commission_errors, no_of_ommission_errors, mean_reaction_time, total_duration});
Toast.makeText(this, "Data Added Successfully", Toast.LENGTH_SHORT).show(); //Toast.makeText(this, "Data Added Successfully", Toast.LENGTH_SHORT).show();
} }
/*************************************************************************************************/ /*************************************************************************************************/
......
package com.anuththara18.attentionassessment.splashscreen; package com.anuththara18.attentionassessment.splashscreen;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.view.View; import android.view.View;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.Toast;
import com.anuththara18.attentionassessment.R; import com.anuththara18.attentionassessment.R;
import com.anuththara18.attentionassessment.details.ParentDetailsActivity;
import com.anuththara18.attentionassessment.language.LanguageActivity; import com.anuththara18.attentionassessment.language.LanguageActivity;
import com.anuththara18.attentionassessment.language.LanguageSetter;
public class SplashActivity extends AppCompatActivity { public class SplashActivity extends AppCompatActivity {
SharedPreferences sharedPreferences;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
sharedPreferences = getSharedPreferences("Language", MODE_PRIVATE);
SharedPreferences.Editor ed = sharedPreferences.edit();
String lang = sharedPreferences.getString("Lang", "");
//int check = sharedPreferences.getInt("ImageCheck", 5);
if (Build.VERSION.SDK_INT < 16) { if (Build.VERSION.SDK_INT < 16) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); WindowManager.LayoutParams.FLAG_FULLSCREEN);
...@@ -27,11 +38,20 @@ public class SplashActivity extends AppCompatActivity { ...@@ -27,11 +38,20 @@ public class SplashActivity extends AppCompatActivity {
setContentView(R.layout.activity_splash); setContentView(R.layout.activity_splash);
Handler handler = new Handler(); Handler handler = new Handler();
//Toast.makeText(getApplicationContext(), String.valueOf(check), Toast.LENGTH_SHORT).show();
handler.postDelayed(new Runnable() { handler.postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {
Intent intent = new Intent(SplashActivity.this, LanguageActivity.class); if(lang.isEmpty()){
startActivity(intent); Intent langAct = new Intent(SplashActivity.this, LanguageActivity.class);
startActivity(langAct);
}
else{
Intent parentAct = new Intent(SplashActivity.this, ParentDetailsActivity.class);
startActivity(parentAct);
LanguageSetter.setLanguage(lang);
LanguageSetter.changeLanguage(lang, SplashActivity.this);
}
finish(); finish();
} }
},2000); },2000);
......
...@@ -338,7 +338,7 @@ public class SA1CompleteScreen extends AppCompatActivity { ...@@ -338,7 +338,7 @@ public class SA1CompleteScreen extends AppCompatActivity {
// below line is to print toast message // below line is to print toast message
// on completion of PDF generation. // on completion of PDF generation.
Toast.makeText(getApplicationContext(), "PDF file generated successfully.", Toast.LENGTH_LONG).show(); //Toast.makeText(getApplicationContext(), "PDF file generated successfully.", Toast.LENGTH_LONG).show();
} catch (IOException e) { } catch (IOException e) {
// below line is used // below line is used
......
...@@ -408,7 +408,7 @@ public class SustainedAttentionGame1 extends AppCompatActivity { ...@@ -408,7 +408,7 @@ public class SustainedAttentionGame1 extends AppCompatActivity {
mDatabase.execSQL(insertSQL, new Integer[]{child_ID, total_correct_responses, no_of_correct_responses, no_of_ommission_errors, no_of_commission_errors, mean_reaction_time, total_duration}); mDatabase.execSQL(insertSQL, new Integer[]{child_ID, total_correct_responses, no_of_correct_responses, no_of_ommission_errors, no_of_commission_errors, mean_reaction_time, total_duration});
Toast.makeText(this, "Data Added Successfully", Toast.LENGTH_SHORT).show(); //Toast.makeText(this, "Data Added Successfully", Toast.LENGTH_SHORT).show();
} }
......
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