Commit 72ca270b authored by Anuththara18's avatar Anuththara18

Saving Parent's Details to local database

parent 5ae42c2c
......@@ -4,6 +4,8 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.util.DisplayMetrics;
......@@ -16,16 +18,26 @@ import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.anuththara18.attentionassessment.R;
import com.anuththara18.attentionassessment.consentform.ConsentFormActivity;
import com.anuththara18.attentionassessment.consentform.SinhalaConsentFormActivity;
import com.anuththara18.attentionassessment.db.Api;
import com.anuththara18.attentionassessment.db.RequestHandler;
import com.anuththara18.attentionassessment.details.ParentDetailsActivity;
import com.anuththara18.attentionassessment.focused.FocusedAttentionGame1;
import com.anuththara18.attentionassessment.gender.GenderActivity;
import com.anuththara18.attentionassessment.home.NavigationDrawerActivity;
import com.anuththara18.attentionassessment.language.LanguageActivity;
import com.anuththara18.attentionassessment.language.LanguageSetter;
import com.anuththara18.attentionassessment.selective.SelectiveAttentionGame1;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
public class AgeActivity extends AppCompatActivity {
ImageButton right_btn, left_btn;
......@@ -37,6 +49,12 @@ public class AgeActivity extends AppCompatActivity {
int count;
float rightFromXDelta, rightToXDelta, leftFromXDelta, leftToXDelta;
public static final String DATABASE_NAME = "childData";
SQLiteDatabase mDatabase;
private static final int CODE_GET_REQUEST = 1024;
private static final int CODE_POST_REQUEST = 1025;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -57,6 +75,8 @@ public class AgeActivity extends AppCompatActivity {
previous = (TextView)findViewById(R.id.previous);
selectAge = (TextView)findViewById(R.id.selectAge);
mDatabase = openOrCreateDatabase(DATABASE_NAME, MODE_PRIVATE, null);
next.setText(LanguageSetter.getresources().getString(R.string.next));
previous.setText(LanguageSetter.getresources().getString(R.string.previous));
selectAge.setText(LanguageSetter.getresources().getString(R.string.age));
......@@ -106,15 +126,17 @@ public class AgeActivity extends AppCompatActivity {
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
/*
//saveDataToOnlineDB();
createTable();
saveDataToLocalDB();
if ( LanguageActivity.text.equals("English")) {
startActivity(new Intent(AgeActivity.this, ConsentFormActivity.class));
}
else {
startActivity(new Intent(AgeActivity.this, SinhalaConsentFormActivity.class));
}
*/
startActivity(new Intent(AgeActivity.this, NavigationDrawerActivity.class));
//startActivity(new Intent(AgeActivity.this, NavigationDrawerActivity.class));
}
});
......@@ -128,6 +150,8 @@ public class AgeActivity extends AppCompatActivity {
}
/*************************************************************************************************/
public void getDimensions() {
if ( count == 1 ) {
leftFromXDelta = 0;
......@@ -153,6 +177,8 @@ public class AgeActivity extends AppCompatActivity {
}
}
/*************************************************************************************************/
public void setAge() {
if ( count == 1 ) {
age = 4;
......@@ -179,4 +205,142 @@ public class AgeActivity extends AppCompatActivity {
Log.d("age", String.valueOf(age));
}
}
/*************************************************************************************************/
/*
private void saveDataToOnlineDB() {
String gender;
if (GenderActivity.gender == 2) {
gender = "Male";
}
else {
gender = "Female";
}
String age = String.valueOf(AgeActivity.age);
String name = ParentDetailsActivity.child_name;
String email = ParentDetailsActivity.parent_email;
String contact = ParentDetailsActivity.parent_contact;
HashMap<String, String> params = new HashMap<>();
params.put("child_gender", gender);
params.put("child_age", age);
params.put("child_name", name);
params.put("parent_email", email);
params.put("parent_contact", contact);
PerformNetworkRequest request = new PerformNetworkRequest(Api.URL_FOCUSED_ATTENTION, params, CODE_POST_REQUEST);
request.execute();
}
*/
/*************************************************************************************************/
/*
//inner class to perform network request extending an AsyncTask
private class PerformNetworkRequest extends AsyncTask<Void, Void, String> {
//the url where we need to send the request
String url;
//the parameters
HashMap<String, String> params;
//the request code to define whether it is a GET or POST
int requestCode;
//constructor to initialize values
PerformNetworkRequest(String url, HashMap<String, String> params, int requestCode) {
this.url = url;
this.params = params;
this.requestCode = requestCode;
}
//when the task started displaying a progressbar
@Override
protected void onPreExecute() {
super.onPreExecute();
}
//this method will give the response from the request
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
try {
JSONObject object = new JSONObject(s);
if (!object.getBoolean("error")) {
Toast.makeText(getApplicationContext(), object.getString("message"), Toast.LENGTH_SHORT).show();
//refreshing the herolist after every operation
//so we get an updated list
//we will create this method right now it is commented
//because we haven't created it yet
//refreshHeroList(object.getJSONArray("heroes"));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
//the network operation will be performed in background
@Override
protected String doInBackground(Void... voids) {
RequestHandler requestHandler = new RequestHandler();
if (requestCode == CODE_POST_REQUEST)
return requestHandler.sendPostRequest(url, params);
if (requestCode == CODE_GET_REQUEST)
return requestHandler.sendGetRequest(url);
return null;
}
}
*/
/*************************************************************************************************/
private void createTable() {
mDatabase.execSQL(
"CREATE TABLE IF NOT EXISTS childData (\n" +
" id INTEGER PRIMARY KEY AUTOINCREMENT,\n" +
" child_gender String NOT NULL,\n" +
" child_age String NOT NULL,\n" +
" child_name String ,\n" +
" parent_email String ,\n" +
" parent_contact String \n" +
");"
);
}
/*************************************************************************************************/
private void saveDataToLocalDB() {
String gender;
if (GenderActivity.gender == 2) {
gender = "Male";
}
else {
gender = "Female";
}
String age = String.valueOf(AgeActivity.age);
String name = ParentDetailsActivity.child_name;
String email = ParentDetailsActivity.parent_email;
String contact = ParentDetailsActivity.parent_contact;
String insertSQL = "INSERT INTO childData \n" +
"(child_gender, child_age, child_name, parent_email, parent_contact)\n" +
"VALUES \n" +
"(?, ?, ?, ?, ?);";
mDatabase.execSQL(insertSQL, new String[]{gender, age, name, email, contact});
Toast.makeText(this, "Data Added Successfully", Toast.LENGTH_SHORT).show();
}
/*************************************************************************************************/
}
\ No newline at end of file
......@@ -28,6 +28,7 @@ import androidx.core.content.ContextCompat;
import com.anuththara18.attentionassessment.R;
import com.anuththara18.attentionassessment.age.AgeActivity;
import com.anuththara18.attentionassessment.consentform.ParentsConsentDatabaseHelper;
import com.anuththara18.attentionassessment.details.ParentDetailsActivity;
import com.anuththara18.attentionassessment.gender.GenderActivity;
import com.anuththara18.attentionassessment.home.NavigationDrawerActivity;
import com.anuththara18.attentionassessment.selective.Selective;
......@@ -263,13 +264,9 @@ public class AACompleteScreen extends AppCompatActivity {
gender = "Female";
}
canvas.drawText("Gender: " + gender, 150, 300, title);
/*
canvas.drawText("Child Name: " + gender, 150, 350, title);
canvas.drawText("Parent Name: " + gender, 150, 400, title);
canvas.drawText("Contact No: " + gender, 150, 450, title);
canvas.drawText("Email: " + gender, 150, 500, title);
*/
canvas.drawText("Child Name: " + ParentDetailsActivity.child_name, 150, 350, title);
canvas.drawText("Contact No: " + ParentDetailsActivity.parent_contact, 150, 450, title);
canvas.drawText("Email: " + ParentDetailsActivity.parent_email, 150, 500, title);
// similarly we are creating another text and in this
// we are aligning this text to center of our PDF file.
......@@ -303,7 +300,7 @@ public class AACompleteScreen extends AppCompatActivity {
"CE: " + String.valueOf(data.getNoOfCommissionErrors()) + ", \t" +
"OE: " + String.valueOf(data.getNoOfOmmissionErrors()) + ", \t" +
"MRT: " + String.valueOf(data.getMeanReactionTime()) + ", \t" +
"TD: " + String.valueOf(data.getTotalDuration()) + " ", 150, 350 + space, title);
"TD: " + String.valueOf(data.getTotalDuration()) + " ", 150, 550 + space, title);
space = space + 50;
}
......
......@@ -19,8 +19,9 @@ import com.anuththara18.attentionassessment.language.LanguageSetter;
public class ParentDetailsActivity extends AppCompatActivity {
TextView name, email, contact, next, previous;
TextView name, email, contact, next, previous, opt1, opt2, opt3;
EditText childName, parentEmail, parentContact;
public static String child_name, parent_email, parent_contact;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -39,6 +40,9 @@ public class ParentDetailsActivity extends AppCompatActivity {
contact = findViewById(R.id.contact);
next = findViewById(R.id.next);
previous = findViewById(R.id.previous);
opt1 = findViewById(R.id.opt1);
opt2 = findViewById(R.id.opt2);
opt3 = findViewById(R.id.opt3);
childName = findViewById(R.id.childName);
parentEmail = findViewById(R.id.parentEmail);
......@@ -49,6 +53,13 @@ public class ParentDetailsActivity extends AppCompatActivity {
name.setText(LanguageSetter.getresources().getString(R.string.childName));
email.setText(LanguageSetter.getresources().getString(R.string.parentEmail));
contact.setText(LanguageSetter.getresources().getString(R.string.parentContact));
opt1.setText(LanguageSetter.getresources().getString(R.string.optional));
opt2.setText(LanguageSetter.getresources().getString(R.string.optional));
opt3.setText(LanguageSetter.getresources().getString(R.string.optional));
child_name = childName.getText().toString();
parent_email = parentEmail.getText().toString();
parent_contact = parentContact.getText().toString();
previous.setOnClickListener(new View.OnClickListener() {
@Override
......
......@@ -32,6 +32,7 @@ import com.anuththara18.attentionassessment.BuildConfig;
import com.anuththara18.attentionassessment.R;
import com.anuththara18.attentionassessment.age.AgeActivity;
import com.anuththara18.attentionassessment.consentform.ParentsConsentDatabaseHelper;
import com.anuththara18.attentionassessment.details.ParentDetailsActivity;
import com.anuththara18.attentionassessment.gender.GenderActivity;
import com.anuththara18.attentionassessment.home.NavigationDrawerActivity;
import com.anuththara18.attentionassessment.selective.Selective;
......@@ -265,12 +266,9 @@ public class DACompleteScreen extends AppCompatActivity {
gender = "Female";
}
canvas.drawText("Gender: " + gender, 150, 300, title);
/*
canvas.drawText("Child Name: " + gender, 150, 350, title);
canvas.drawText("Parent Name: " + gender, 150, 400, title);
canvas.drawText("Contact No: " + gender, 150, 450, title);
canvas.drawText("Email: " + gender, 150, 500, title);
*/
canvas.drawText("Child Name: " + ParentDetailsActivity.child_name, 150, 350, title);
canvas.drawText("Contact No: " + ParentDetailsActivity.parent_contact, 150, 450, title);
canvas.drawText("Email: " + ParentDetailsActivity.parent_email, 150, 500, title);
// similarly we are creating another text and in this
// we are aligning this text to center of our PDF file.
......@@ -304,7 +302,7 @@ public class DACompleteScreen extends AppCompatActivity {
"CE: " + String.valueOf(data.getNoOfCommissionErrors()) + ", \t" +
"OE: " + String.valueOf(data.getNoOfOmmissionErrors()) + ", \t" +
"MRT: " + String.valueOf(data.getMeanReactionTime()) + ", \t" +
"TD: " + String.valueOf(data.getTotalDuration()) + " ", 150, 350 + space, title);
"TD: " + String.valueOf(data.getTotalDuration()) + " ", 150, 550 + space, title);
space = space + 50;
}
......
......@@ -32,6 +32,7 @@ import com.anuththara18.attentionassessment.BuildConfig;
import com.anuththara18.attentionassessment.R;
import com.anuththara18.attentionassessment.age.AgeActivity;;
import com.anuththara18.attentionassessment.consentform.ParentsConsentDatabaseHelper;
import com.anuththara18.attentionassessment.details.ParentDetailsActivity;
import com.anuththara18.attentionassessment.gender.GenderActivity;
import com.anuththara18.attentionassessment.home.NavigationDrawerActivity;
import com.anuththara18.attentionassessment.selective.Selective;
......@@ -266,13 +267,9 @@ public class FACompleteScreen extends AppCompatActivity {
gender = "Female";
}
canvas.drawText("Gender: " + gender, 150, 300, title);
/*
canvas.drawText("Child Name: " + gender, 150, 350, title);
canvas.drawText("Parent Name: " + gender, 150, 400, title);
canvas.drawText("Contact No: " + gender, 150, 450, title);
canvas.drawText("Email: " + gender, 150, 500, title);
*/
canvas.drawText("Child Name: " + ParentDetailsActivity.child_name, 150, 350, title);
canvas.drawText("Contact No: " + ParentDetailsActivity.parent_contact, 150, 450, title);
canvas.drawText("Email: " + ParentDetailsActivity.parent_email, 150, 500, title);
// similarly we are creating another text and in this
// we are aligning this text to center of our PDF file.
......@@ -306,7 +303,7 @@ public class FACompleteScreen extends AppCompatActivity {
"CE: " + String.valueOf(data.getNoOfCommissionErrors()) + ", \t" +
"OE: " + String.valueOf(data.getNoOfOmmissionErrors()) + ", \t" +
"MRT: " + String.valueOf(data.getMeanReactionTime()) + ", \t" +
"TD: " + String.valueOf(data.getTotalDuration()) + " ", 150, 350 + space, title);
"TD: " + String.valueOf(data.getTotalDuration()) + " ", 150,550 + space, title);
space = space + 50;
}
......@@ -324,23 +321,6 @@ public class FACompleteScreen extends AppCompatActivity {
// write our PDF file to that location.
pdfDocument.writeTo(new FileOutputStream(file));
/*
// Uri path = Uri.fromFile(file);
Uri path = FileProvider.getUriForFile(FACompleteScreen.this, BuildConfig.APPLICATION_ID + ".provider", file);
Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
pdfIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
pdfIntent.setDataAndType(path, "application/pdf");
pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try{
startActivity(pdfIntent);
}catch(ActivityNotFoundException e){
Toast.makeText(getApplicationContext(), "No Application available to view PDF", Toast.LENGTH_SHORT).show();
}
*/
// below line is to print toast message
// on completion of PDF generation.
Toast.makeText(getApplicationContext(), "PDF file generated successfully.", Toast.LENGTH_LONG).show();
......@@ -380,15 +360,6 @@ public class FACompleteScreen extends AppCompatActivity {
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;
......
......@@ -21,7 +21,7 @@ public class LanguageActivity extends AppCompatActivity {
ImageButton english_btn, sinhala_btn, sinhala_txt_btn;
TextView english_txt;
public static String text = "English";
public static String text = null;
TextView selectLanguage, next;
@Override
......
......@@ -32,6 +32,7 @@ import com.anuththara18.attentionassessment.BuildConfig;
import com.anuththara18.attentionassessment.R;
import com.anuththara18.attentionassessment.age.AgeActivity;
import com.anuththara18.attentionassessment.consentform.ParentsConsentDatabaseHelper;
import com.anuththara18.attentionassessment.details.ParentDetailsActivity;
import com.anuththara18.attentionassessment.gender.GenderActivity;
import com.anuththara18.attentionassessment.home.NavigationDrawerActivity;
import com.opencsv.CSVWriter;
......@@ -108,7 +109,6 @@ public class SelectiveACompleteScreen extends AppCompatActivity {
e.printStackTrace();
}
// initializing our variables.
bmp = BitmapFactory.decodeResource(getResources(), R.drawable.selective);
scaledbmp = Bitmap.createScaledBitmap(bmp, 140, 140, false);
......@@ -231,13 +231,9 @@ public class SelectiveACompleteScreen extends AppCompatActivity {
gender = "Female";
}
canvas.drawText("Gender: " + gender, 150, 300, title);
/*
canvas.drawText("Child Name: " + gender, 150, 350, title);
canvas.drawText("Parent Name: " + gender, 150, 400, title);
canvas.drawText("Contact No: " + gender, 150, 450, title);
canvas.drawText("Email: " + gender, 150, 500, title);
*/
canvas.drawText("Child Name: " + ParentDetailsActivity.child_name, 150, 350, title);
canvas.drawText("Contact No: " + ParentDetailsActivity.parent_contact, 150, 450, title);
canvas.drawText("Email: " + ParentDetailsActivity.parent_email, 150, 500, title);
title.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
title.setColor(ContextCompat.getColor(this, R.color.black));
......@@ -267,7 +263,7 @@ public class SelectiveACompleteScreen extends AppCompatActivity {
"CE: " + String.valueOf(data.getNoOfCommissionErrors()) + ", \t" +
"OE: " + String.valueOf(data.getNoOfOmmissionErrors()) + ", \t" +
"MRT: " + String.valueOf(data.getMeanReactionTime()) + ", \t" +
"TD: " + String.valueOf(data.getTotalDuration()) + " ", 150, 350 + space, title);
"TD: " + String.valueOf(data.getTotalDuration()) + " ", 150, 550 + space, title);
space = space + 50;
}
......
......@@ -32,6 +32,7 @@ import com.anuththara18.attentionassessment.BuildConfig;
import com.anuththara18.attentionassessment.R;
import com.anuththara18.attentionassessment.age.AgeActivity;
import com.anuththara18.attentionassessment.consentform.ParentsConsentDatabaseHelper;
import com.anuththara18.attentionassessment.details.ParentDetailsActivity;
import com.anuththara18.attentionassessment.gender.GenderActivity;
import com.anuththara18.attentionassessment.home.NavigationDrawerActivity;
import com.anuththara18.attentionassessment.selective.Selective;
......@@ -68,7 +69,6 @@ public class SA1CompleteScreen extends AppCompatActivity {
// constant code for runtime permissions
private static final int PERMISSION_REQUEST_CODE = 200;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -265,13 +265,9 @@ public class SA1CompleteScreen extends AppCompatActivity {
gender = "Female";
}
canvas.drawText("Gender: " + gender, 150, 300, title);
/*
canvas.drawText("Child Name: " + gender, 150, 350, title);
canvas.drawText("Parent Name: " + gender, 150, 400, title);
canvas.drawText("Contact No: " + gender, 150, 450, title);
canvas.drawText("Email: " + gender, 150, 500, title);
*/
canvas.drawText("Child Name: " + ParentDetailsActivity.child_name, 150, 350, title);
canvas.drawText("Contact No: " + ParentDetailsActivity.parent_contact, 150, 450, title);
canvas.drawText("Email: " + ParentDetailsActivity.parent_email, 150, 500, title);
// similarly we are creating another text and in this
// we are aligning this text to center of our PDF file.
......@@ -305,7 +301,7 @@ public class SA1CompleteScreen extends AppCompatActivity {
"CE: " + String.valueOf(data.getNoOfCommissionErrors()) + ", \t" +
"OE: " + String.valueOf(data.getNoOfOmmissionErrors()) + ", \t" +
"MRT: " + String.valueOf(data.getMeanReactionTime()) + ", \t" +
"TD: " + String.valueOf(data.getTotalDuration()) + " ", 150, 350 + space, title);
"TD: " + String.valueOf(data.getTotalDuration()) + " ", 150, 550 + space, title);
space = space + 50;
}
......
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