Commit 5885d509 authored by Anuththara18's avatar Anuththara18

Consent Form Integration & Saving parent's signature

parent f2899e35
...@@ -9,7 +9,7 @@ android { ...@@ -9,7 +9,7 @@ android {
defaultConfig { defaultConfig {
applicationId "com.anuththara18.attentionassessment" applicationId "com.anuththara18.attentionassessment"
minSdkVersion 24 minSdkVersion 24
targetSdkVersion 31 targetSdkVersion 29
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
......
...@@ -34,7 +34,8 @@ ...@@ -34,7 +34,8 @@
<activity <activity
android:name=".consentform.ConsentFormActivity" android:name=".consentform.ConsentFormActivity"
android:screenOrientation="portrait" android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar"></activity> android:theme="@style/Theme.AppCompat.NoActionBar">
</activity>
<activity <activity
android:name=".consentform.GetParentsConsentActivity" android:name=".consentform.GetParentsConsentActivity"
android:screenOrientation="portrait" android:screenOrientation="portrait"
......
...@@ -18,6 +18,7 @@ import android.widget.RelativeLayout; ...@@ -18,6 +18,7 @@ import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import com.anuththara18.attentionassessment.R; import com.anuththara18.attentionassessment.R;
import com.anuththara18.attentionassessment.consentform.ConsentFormActivity;
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.LanguageActivity; import com.anuththara18.attentionassessment.language.LanguageActivity;
...@@ -104,7 +105,7 @@ public class AgeActivity extends AppCompatActivity { ...@@ -104,7 +105,7 @@ public class AgeActivity extends AppCompatActivity {
next.setOnClickListener(new View.OnClickListener() { next.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
Intent intent = new Intent(AgeActivity.this, NavigationDrawerActivity.class); Intent intent = new Intent(AgeActivity.this, ConsentFormActivity.class);
startActivity(intent); startActivity(intent);
} }
}); });
......
...@@ -50,7 +50,7 @@ public class AACompleteScreen extends AppCompatActivity { ...@@ -50,7 +50,7 @@ public class AACompleteScreen extends AppCompatActivity {
// declaring width and height // declaring width and height
// for our PDF file. // for our PDF file.
int pageHeight = 1120; int pageHeight = 1520;
int pagewidth = 792; int pagewidth = 792;
// creating a bitmap variable // creating a bitmap variable
......
package com.anuththara18.attentionassessment.consentform; package com.anuththara18.attentionassessment.consentform;
import android.Manifest; import android.Manifest;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
...@@ -19,9 +25,17 @@ import androidx.core.content.ContextCompat; ...@@ -19,9 +25,17 @@ import androidx.core.content.ContextCompat;
import com.anuththara18.attentionassessment.R; import com.anuththara18.attentionassessment.R;
import com.anuththara18.attentionassessment.home.NavigationDrawerActivity;
import com.anuththara18.attentionassessment.language.LanguageSetter; import com.anuththara18.attentionassessment.language.LanguageSetter;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
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 GetParentsConsentActivity extends AppCompatActivity { public class GetParentsConsentActivity extends AppCompatActivity {
...@@ -30,8 +44,11 @@ public class GetParentsConsentActivity extends AppCompatActivity { ...@@ -30,8 +44,11 @@ public class GetParentsConsentActivity extends AppCompatActivity {
public static ImageView fingerprintImageView; public static ImageView fingerprintImageView;
static int flag2 = 0; static int flag2 = 0;
private static final int STORAGE_PERMISSION_CODE = 101; // constant code for runtime permissions
private static final int PERMISSION_REQUEST_CODE = 200;
public static ParentsConsentDatabaseHelper sqLiteHelper;
private static final int STORAGE_PERMISSION_CODE = 101;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -47,9 +64,21 @@ public class GetParentsConsentActivity extends AppCompatActivity { ...@@ -47,9 +64,21 @@ public class GetParentsConsentActivity extends AppCompatActivity {
//btnSaveFingerPrint.setText(LanguageSetter.getresources().getString(R.string.startTest)); //btnSaveFingerPrint.setText(LanguageSetter.getresources().getString(R.string.startTest));
//btnGetSignature.setText(LanguageSetter.getresources().getString(R.string.getSignature)); //btnGetSignature.setText(LanguageSetter.getresources().getString(R.string.getSignature));
checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, STORAGE_PERMISSION_CODE); /*******************************************************************************************/
// below code is used for
// checking our permissions.
if (checkPermission()) {
//Toast.makeText(this, "Permission Granted", Toast.LENGTH_SHORT).show();
} else {
requestPermission();
}
/*******************************************************************************************/
sqLiteHelper = new ParentsConsentDatabaseHelper(this, "ParentsConsent.sqlite", null, 1);
sqLiteHelper.queryData("CREATE TABLE IF NOT EXISTS ParentsConsent(signature BLOB)");
/************************************************************************************/ /************************************************************************************/
...@@ -58,8 +87,6 @@ public class GetParentsConsentActivity extends AppCompatActivity { ...@@ -58,8 +87,6 @@ public class GetParentsConsentActivity extends AppCompatActivity {
public void onClick(View view) { public void onClick(View view) {
if ( flag2 == 1) { if ( flag2 == 1) {
saveImage(); saveImage();
//Intent intent = new Intent(getApplicationContext(), QuestionnaireMainScreen.class);
//startActivity(intent);
} }
else if ( flag2 == 0 ){ else if ( flag2 == 0 ){
Toast.makeText(getApplicationContext(), "Please Provide your Signature", Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), "Please Provide your Signature", Toast.LENGTH_SHORT).show();
...@@ -86,12 +113,10 @@ public class GetParentsConsentActivity extends AppCompatActivity { ...@@ -86,12 +113,10 @@ public class GetParentsConsentActivity extends AppCompatActivity {
public void saveImage() { public void saveImage() {
try{ try{
/************************************************ sqLiteHelper.insertData(imageViewToByte(fingerprintImageView));
* **********************************************
* **********************************************
*/
Toast.makeText(getApplicationContext(), "Consent Saved Successfully!", Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), "Consent Saved Successfully!", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getApplicationContext(), NavigationDrawerActivity.class);
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();
...@@ -111,43 +136,54 @@ public class GetParentsConsentActivity extends AppCompatActivity { ...@@ -111,43 +136,54 @@ public class GetParentsConsentActivity extends AppCompatActivity {
return byteArray; return byteArray;
} }
/************************************************************************************/ /**************************************************************************************************/
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;
}
// Function to check and request permission. /**************************************************************************************************/
public void checkPermission(String permission, int requestCode)
{
if (ContextCompat.checkSelfPermission(com.anuththara18.attentionassessment.consentform.GetParentsConsentActivity.this, permission) == PackageManager.PERMISSION_DENIED) {
// Requesting the permission private void requestPermission() {
ActivityCompat.requestPermissions(com.anuththara18.attentionassessment.consentform.GetParentsConsentActivity.this, new String[] { permission }, requestCode); // requesting permissions if not provided.
ActivityCompat.requestPermissions(this, new String[]{WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE, MANAGE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE);
} }
else {
//Toast.makeText(GetParentsConsentActivity.this, "Permission already granted", Toast.LENGTH_SHORT).show();
}
}
// This function is called when the user accepts or decline the permission.
// Request Code is used to check which permission called this function.
// This request code is provided when the user is prompt for permission.
@Override @Override
public void onRequestPermissionsResult(int requestCode, public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
@NonNull String[] permissions, super.onRequestPermissionsResult(requestCode, permissions, grantResults);
@NonNull int[] grantResults) if (requestCode == PERMISSION_REQUEST_CODE) {
{ if (grantResults.length > 0) {
super.onRequestPermissionsResult(requestCode,
permissions, /*
grantResults); Intent intent = new Intent();
intent.setAction(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
if (requestCode == STORAGE_PERMISSION_CODE) { Uri uri = Uri.fromParts("package", this.getPackageName(), null);
if (grantResults.length > 0 intent.setData(uri);
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) { startActivity(intent);
Toast.makeText(com.anuththara18.attentionassessment.consentform.GetParentsConsentActivity.this, "Storage Permission Granted", Toast.LENGTH_SHORT).show();
*/
// 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 { } else {
Toast.makeText(com.anuththara18.attentionassessment.consentform.GetParentsConsentActivity.this, "Storage Permission Denied", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "Permission Denined.", Toast.LENGTH_SHORT).show();
finish();
}
} }
} }
} }
/**************************************************************************************************/
} }
\ No newline at end of file
package com.anuththara18.attentionassessment.consentform;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteStatement;
public class ParentsConsentDatabaseHelper extends SQLiteOpenHelper {
public ParentsConsentDatabaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, version);
}
public void queryData(String sql){
SQLiteDatabase database = getWritableDatabase();
database.execSQL(sql);
}
public void insertData(byte[] image){
SQLiteDatabase database = getWritableDatabase();
String sql = "INSERT INTO ParentsConsent VALUES (?)";
SQLiteStatement statement = database.compileStatement(sql);
statement.clearBindings();
statement.bindBlob(1, image);
statement.executeInsert();
}
public Cursor getData(String sql){
SQLiteDatabase database = getReadableDatabase();
return database.rawQuery(sql, null);
}
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
}
}
package com.anuththara18.attentionassessment.consentform;
import java.io.Serializable;
public class ParentsConsentModel implements Serializable {
private byte[] signature;
public ParentsConsentModel(byte[] signature) {
this.signature = signature;
}
public byte[] getSignature() {
return signature;
}
public void setSignature(byte[] signature) {
this.signature = signature;
}
}
...@@ -52,7 +52,7 @@ public class DACompleteScreen extends AppCompatActivity { ...@@ -52,7 +52,7 @@ public class DACompleteScreen extends AppCompatActivity {
// declaring width and height // declaring width and height
// for our PDF file. // for our PDF file.
int pageHeight = 1120; int pageHeight = 1520;
int pagewidth = 792; int pagewidth = 792;
// creating a bitmap variable // creating a bitmap variable
......
...@@ -52,7 +52,7 @@ public class FACompleteScreen extends AppCompatActivity { ...@@ -52,7 +52,7 @@ public class FACompleteScreen extends AppCompatActivity {
// declaring width and height // declaring width and height
// for our PDF file. // for our PDF file.
int pageHeight = 1120; int pageHeight = 1520;
int pagewidth = 792; int pagewidth = 792;
// creating a bitmap variable // creating a bitmap variable
......
...@@ -8,6 +8,7 @@ import android.database.sqlite.SQLiteDatabase; ...@@ -8,6 +8,7 @@ import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.graphics.pdf.PdfDocument; import android.graphics.pdf.PdfDocument;
...@@ -30,6 +31,7 @@ import androidx.core.content.FileProvider; ...@@ -30,6 +31,7 @@ import androidx.core.content.FileProvider;
import com.anuththara18.attentionassessment.BuildConfig; import com.anuththara18.attentionassessment.BuildConfig;
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.consentform.ParentsConsentDatabaseHelper;
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.opencsv.CSVWriter; import com.opencsv.CSVWriter;
...@@ -54,12 +56,13 @@ public class SelectiveACompleteScreen extends AppCompatActivity { ...@@ -54,12 +56,13 @@ public class SelectiveACompleteScreen extends AppCompatActivity {
// declaring width and height // declaring width and height
// for our PDF file. // for our PDF file.
int pageHeight = 1120; int pageHeight = 1520;
int pagewidth = 792; int pagewidth = 792;
// creating a bitmap variable // creating a bitmap variable
// for storing our images // for storing our images
Bitmap bmp, scaledbmp; Bitmap bmp, bmp2, scaledbmp, scaledbmp2;
public static ParentsConsentDatabaseHelper sqLiteHelper;
// 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;
...@@ -77,6 +80,8 @@ public class SelectiveACompleteScreen extends AppCompatActivity { ...@@ -77,6 +80,8 @@ public class SelectiveACompleteScreen extends AppCompatActivity {
decorView.setSystemUiVisibility(uiOptions); decorView.setSystemUiVisibility(uiOptions);
setContentView(R.layout.activity_complete_screen2); setContentView(R.layout.activity_complete_screen2);
sqLiteHelper = new ParentsConsentDatabaseHelper(this, "ParentsConsent.sqlite", null, 1);
complete = findViewById(R.id.complete); complete = findViewById(R.id.complete);
complete.setOnClickListener(new View.OnClickListener() { complete.setOnClickListener(new View.OnClickListener() {
...@@ -90,9 +95,25 @@ public class SelectiveACompleteScreen extends AppCompatActivity { ...@@ -90,9 +95,25 @@ public class SelectiveACompleteScreen extends AppCompatActivity {
/*******************************************************************************************/ /*******************************************************************************************/
try {
Cursor cursor = sqLiteHelper.getData("SELECT * FROM ParentsConsent");
while (cursor.moveToNext()) {
byte[] image = cursor.getBlob(0);
bmp2 = BitmapFactory.decodeByteArray(image, 0, image.length);
//fingerprintImageView.setImageBitmap(bmp);
}
}
catch (Exception e) {
e.printStackTrace();
}
// initializing our variables. // initializing our variables.
bmp = BitmapFactory.decodeResource(getResources(), R.drawable.selective); bmp = BitmapFactory.decodeResource(getResources(), R.drawable.selective);
scaledbmp = Bitmap.createScaledBitmap(bmp, 140, 140, false); scaledbmp = Bitmap.createScaledBitmap(bmp, 140, 140, false);
//scaledbmp2 = Bitmap.createScaledBitmap(bmp2, 200, 200, false);
scaledbmp2 = BITMAP_RESIZER(bmp2, 400, 400);
// below code is used for // below code is used for
// checking our permissions. // checking our permissions.
...@@ -186,6 +207,7 @@ public class SelectiveACompleteScreen extends AppCompatActivity { ...@@ -186,6 +207,7 @@ public class SelectiveACompleteScreen extends AppCompatActivity {
Canvas canvas = myPage.getCanvas(); Canvas canvas = myPage.getCanvas();
canvas.drawBitmap(scaledbmp, 56, 40, paint); canvas.drawBitmap(scaledbmp, 56, 40, paint);
canvas.drawBitmap(scaledbmp2, 400, 0, paint);
title.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD)); title.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
title.setTextSize(20); title.setTextSize(20);
...@@ -304,4 +326,22 @@ public class SelectiveACompleteScreen extends AppCompatActivity { ...@@ -304,4 +326,22 @@ public class SelectiveACompleteScreen extends AppCompatActivity {
/**************************************************************************************************/ /**************************************************************************************************/
public Bitmap BITMAP_RESIZER(Bitmap bitmap,int newWidth,int newHeight) {
Bitmap scaledBitmap = Bitmap.createBitmap(newWidth, newHeight, Bitmap.Config.ARGB_8888);
float ratioX = newWidth / (float) bitmap.getWidth();
float ratioY = newHeight / (float) bitmap.getHeight();
float middleX = newWidth / 2.0f;
float middleY = newHeight / 2.0f;
Matrix scaleMatrix = new Matrix();
scaleMatrix.setScale(ratioX, ratioY, middleX, middleY);
Canvas canvas = new Canvas(scaledBitmap);
canvas.setMatrix(scaleMatrix);
canvas.drawBitmap(bitmap, middleX - bitmap.getWidth() / 2, middleY - bitmap.getHeight() / 2, new Paint(Paint.FILTER_BITMAP_FLAG));
return scaledBitmap;
}
} }
...@@ -52,7 +52,7 @@ public class SA1CompleteScreen extends AppCompatActivity { ...@@ -52,7 +52,7 @@ public class SA1CompleteScreen extends AppCompatActivity {
// declaring width and height // declaring width and height
// for our PDF file. // for our PDF file.
int pageHeight = 1120; int pageHeight = 1520;
int pagewidth = 792; int pagewidth = 792;
// creating a bitmap variable // creating a bitmap variable
......
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