Commit 5885d509 authored by Anuththara18's avatar Anuththara18

Consent Form Integration & Saving parent's signature

parent f2899e35
......@@ -9,7 +9,7 @@ android {
defaultConfig {
applicationId "com.anuththara18.attentionassessment"
minSdkVersion 24
targetSdkVersion 31
targetSdkVersion 29
versionCode 1
versionName "1.0"
......
......@@ -34,7 +34,8 @@
<activity
android:name=".consentform.ConsentFormActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar"></activity>
android:theme="@style/Theme.AppCompat.NoActionBar">
</activity>
<activity
android:name=".consentform.GetParentsConsentActivity"
android:screenOrientation="portrait"
......
......@@ -18,6 +18,7 @@ import android.widget.RelativeLayout;
import android.widget.TextView;
import com.anuththara18.attentionassessment.R;
import com.anuththara18.attentionassessment.consentform.ConsentFormActivity;
import com.anuththara18.attentionassessment.gender.GenderActivity;
import com.anuththara18.attentionassessment.home.NavigationDrawerActivity;
import com.anuththara18.attentionassessment.language.LanguageActivity;
......@@ -104,7 +105,7 @@ public class AgeActivity extends AppCompatActivity {
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(AgeActivity.this, NavigationDrawerActivity.class);
Intent intent = new Intent(AgeActivity.this, ConsentFormActivity.class);
startActivity(intent);
}
});
......
......@@ -50,7 +50,7 @@ public class AACompleteScreen extends AppCompatActivity {
// declaring width and height
// for our PDF file.
int pageHeight = 1120;
int pageHeight = 1520;
int pagewidth = 792;
// creating a bitmap variable
......
package com.anuththara18.attentionassessment.consentform;
import android.Manifest;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
......@@ -19,9 +25,17 @@ import androidx.core.content.ContextCompat;
import com.anuththara18.attentionassessment.R;
import com.anuththara18.attentionassessment.home.NavigationDrawerActivity;
import com.anuththara18.attentionassessment.language.LanguageSetter;
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 {
......@@ -30,8 +44,11 @@ public class GetParentsConsentActivity extends AppCompatActivity {
public static ImageView fingerprintImageView;
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
protected void onCreate(Bundle savedInstanceState) {
......@@ -47,9 +64,21 @@ public class GetParentsConsentActivity extends AppCompatActivity {
//btnSaveFingerPrint.setText(LanguageSetter.getresources().getString(R.string.startTest));
//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 {
public void onClick(View view) {
if ( flag2 == 1) {
saveImage();
//Intent intent = new Intent(getApplicationContext(), QuestionnaireMainScreen.class);
//startActivity(intent);
}
else if ( flag2 == 0 ){
Toast.makeText(getApplicationContext(), "Please Provide your Signature", Toast.LENGTH_SHORT).show();
......@@ -86,12 +113,10 @@ public class GetParentsConsentActivity extends AppCompatActivity {
public void saveImage() {
try{
/************************************************
* **********************************************
* **********************************************
*/
sqLiteHelper.insertData(imageViewToByte(fingerprintImageView));
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();
......@@ -111,43 +136,54 @@ public class GetParentsConsentActivity extends AppCompatActivity {
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
ActivityCompat.requestPermissions(com.anuththara18.attentionassessment.consentform.GetParentsConsentActivity.this, new String[] { permission }, requestCode);
private void requestPermission() {
// 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
public void onRequestPermissionsResult(int requestCode,
@NonNull String[] permissions,
@NonNull int[] grantResults)
{
super.onRequestPermissionsResult(requestCode,
permissions,
grantResults);
if (requestCode == STORAGE_PERMISSION_CODE) {
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(com.anuththara18.attentionassessment.consentform.GetParentsConsentActivity.this, "Storage Permission Granted", Toast.LENGTH_SHORT).show();
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
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;
boolean readStorage = grantResults[1] == PackageManager.PERMISSION_GRANTED;
if (writeStorage && readStorage) {
//Toast.makeText(this, "Permission Granted..", Toast.LENGTH_SHORT).show();
} 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 {
// declaring width and height
// for our PDF file.
int pageHeight = 1120;
int pageHeight = 1520;
int pagewidth = 792;
// creating a bitmap variable
......
......@@ -52,7 +52,7 @@ public class FACompleteScreen extends AppCompatActivity {
// declaring width and height
// for our PDF file.
int pageHeight = 1120;
int pageHeight = 1520;
int pagewidth = 792;
// creating a bitmap variable
......
......@@ -8,6 +8,7 @@ import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.graphics.pdf.PdfDocument;
......@@ -30,6 +31,7 @@ import androidx.core.content.FileProvider;
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.gender.GenderActivity;
import com.anuththara18.attentionassessment.home.NavigationDrawerActivity;
import com.opencsv.CSVWriter;
......@@ -54,12 +56,13 @@ public class SelectiveACompleteScreen extends AppCompatActivity {
// declaring width and height
// for our PDF file.
int pageHeight = 1120;
int pageHeight = 1520;
int pagewidth = 792;
// creating a bitmap variable
// for storing our images
Bitmap bmp, scaledbmp;
Bitmap bmp, bmp2, scaledbmp, scaledbmp2;
public static ParentsConsentDatabaseHelper sqLiteHelper;
// constant code for runtime permissions
private static final int PERMISSION_REQUEST_CODE = 200;
......@@ -77,6 +80,8 @@ public class SelectiveACompleteScreen extends AppCompatActivity {
decorView.setSystemUiVisibility(uiOptions);
setContentView(R.layout.activity_complete_screen2);
sqLiteHelper = new ParentsConsentDatabaseHelper(this, "ParentsConsent.sqlite", null, 1);
complete = findViewById(R.id.complete);
complete.setOnClickListener(new View.OnClickListener() {
......@@ -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.
bmp = BitmapFactory.decodeResource(getResources(), R.drawable.selective);
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
// checking our permissions.
......@@ -186,6 +207,7 @@ public class SelectiveACompleteScreen extends AppCompatActivity {
Canvas canvas = myPage.getCanvas();
canvas.drawBitmap(scaledbmp, 56, 40, paint);
canvas.drawBitmap(scaledbmp2, 400, 0, paint);
title.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
title.setTextSize(20);
......@@ -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 {
// declaring width and height
// for our PDF file.
int pageHeight = 1120;
int pageHeight = 1520;
int pagewidth = 792;
// 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