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;
import androidx.constraintlayout.widget.ConstraintLayout;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.os.Build;
......@@ -44,7 +45,8 @@ public class AgeActivity extends AppCompatActivity {
ImageView bunny_img;
TextView age_txt, next, previous, selectAge;
public static int age = 4;
SharedPreferences sharedPreferences;
int imageCheck;
int width;
int count;
float rightFromXDelta, rightToXDelta, leftFromXDelta, leftToXDelta;
......@@ -74,6 +76,8 @@ public class AgeActivity extends AppCompatActivity {
next = (TextView)findViewById(R.id.next);
previous = (TextView)findViewById(R.id.previous);
selectAge = (TextView)findViewById(R.id.selectAge);
sharedPreferences = getSharedPreferences("ImageCheck", MODE_PRIVATE);
imageCheck = sharedPreferences.getInt("ImageSet", 5);
mDatabase = openOrCreateDatabase(DATABASE_NAME, MODE_PRIVATE, null);
......@@ -129,13 +133,23 @@ public class AgeActivity extends AppCompatActivity {
//saveDataToOnlineDB();
createTable();
saveDataToLocalDB();
if ( LanguageActivity.text.equals("English")) {
if (LanguageActivity.text.equals("English")) {
startActivity(new Intent(AgeActivity.this, ConsentFormActivity.class));
}
else {
} else {
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));
}
});
......@@ -338,7 +352,7 @@ public class AgeActivity extends AppCompatActivity {
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 {
// below line is to print toast message
// 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) {
// below line is used
......
......@@ -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});
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;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
......@@ -45,6 +46,8 @@ public class GetParentsConsentActivity extends AppCompatActivity {
Button btnGetSignature;
public static ImageView fingerprintImageView;
static int flag2 = 0;
public SharedPreferences sharedPreferences;
public int imageSet = 0;
// constant code for runtime permissions
private static final int PERMISSION_REQUEST_CODE = 200;
......@@ -68,6 +71,7 @@ public class GetParentsConsentActivity extends AppCompatActivity {
next = (TextView) findViewById(R.id.next);
btnGetSignature = (Button)findViewById(R.id.btnGetSignature);
fingerprintImageView = (ImageView)findViewById(R.id.fingerprintImageView);
sharedPreferences = getSharedPreferences("ImageSet", MODE_PRIVATE);
textView3.setText(LanguageSetter.getresources().getString(R.string.provideconsent));
next.setText(LanguageSetter.getresources().getString(R.string.proceed));
......@@ -127,13 +131,17 @@ public class GetParentsConsentActivity extends AppCompatActivity {
try{
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);
startActivity(intent);
}
catch (Exception e){
Toast.makeText(getApplicationContext(), "Consent not Saved!", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
......@@ -190,6 +198,13 @@ public class GetParentsConsentActivity extends AppCompatActivity {
//Toast.makeText(this, "Permission Granted..", Toast.LENGTH_SHORT).show();
} else {
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();
}
}
......
......@@ -90,7 +90,7 @@ public class GetSignatureActivity extends AppCompatActivity {
GetParentsConsentActivity.fingerprintImageView.setImageBitmap(bitmap);
GetParentsConsentActivity.flag2 = 1;
Toast.makeText(getApplicationContext(), "Signature Recorded", Toast.LENGTH_SHORT).show();
//Toast.makeText(getApplicationContext(), "Signature Recorded", Toast.LENGTH_SHORT).show();
finish();
}
......
......@@ -340,7 +340,7 @@ public class DACompleteScreen extends AppCompatActivity {
// below line is to print toast message
// 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) {
// below line is used
......
......@@ -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});
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 {
// below line is to print toast message
// 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) {
// below line is used
......
......@@ -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});
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;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
......@@ -21,8 +22,10 @@ public class LanguageActivity extends AppCompatActivity {
ImageButton english_btn, sinhala_btn, sinhala_txt_btn;
TextView english_txt;
public static String text = null;
public static String text = "";
public static final String sharedKey = "Language";
TextView selectLanguage, next;
public static SharedPreferences sharedPref;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -42,6 +45,7 @@ public class LanguageActivity extends AppCompatActivity {
english_txt = (TextView) findViewById(R.id.english_txt);
selectLanguage = (TextView) findViewById(R.id.selectLanguage);
next = (TextView) findViewById(R.id.next);
sharedPref = getSharedPreferences(sharedKey, MODE_PRIVATE);
english_btn.setOnClickListener(new View.OnClickListener() {
@Override
......@@ -74,7 +78,7 @@ public class LanguageActivity extends AppCompatActivity {
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if ( text == null ) {
if ( text.isEmpty() ) {
Toast.makeText(getApplicationContext(), "Please select a language", Toast.LENGTH_SHORT).show();
}
else {
......@@ -98,6 +102,7 @@ public class LanguageActivity extends AppCompatActivity {
sinhala_txt_btn.getLayoutParams().width= 394;
sinhala_txt_btn.requestLayout();
text = "English";
setLangPref();
changeLanguage();
}
......@@ -114,6 +119,7 @@ public class LanguageActivity extends AppCompatActivity {
sinhala_txt_btn.getLayoutParams().width= 410;
sinhala_txt_btn.requestLayout();
text = "සිංහල";
setLangPref();
changeLanguage();
}
......@@ -122,7 +128,11 @@ public class LanguageActivity extends AppCompatActivity {
LanguageSetter.changeLanguage(text, LanguageActivity.this);
next.setText(LanguageSetter.getresources().getString(R.string.next));
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 {
try {
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) {
e.printStackTrace();
......
......@@ -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});
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;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.WindowManager;
import android.widget.Toast;
import com.anuththara18.attentionassessment.R;
import com.anuththara18.attentionassessment.details.ParentDetailsActivity;
import com.anuththara18.attentionassessment.language.LanguageActivity;
import com.anuththara18.attentionassessment.language.LanguageSetter;
public class SplashActivity extends AppCompatActivity {
SharedPreferences sharedPreferences;
@Override
protected void onCreate(Bundle 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) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
......@@ -27,11 +38,20 @@ public class SplashActivity extends AppCompatActivity {
setContentView(R.layout.activity_splash);
Handler handler = new Handler();
//Toast.makeText(getApplicationContext(), String.valueOf(check), Toast.LENGTH_SHORT).show();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(SplashActivity.this, LanguageActivity.class);
startActivity(intent);
if(lang.isEmpty()){
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();
}
},2000);
......
......@@ -338,7 +338,7 @@ public class SA1CompleteScreen extends AppCompatActivity {
// below line is to print toast message
// 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) {
// below line is used
......
......@@ -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});
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