Commit de7c1b0c authored by Anuththara18's avatar Anuththara18

Automatic Upload of CSV files

parent 96206ad0
plugins { plugins {
id 'com.android.application' id 'com.android.application'
} }
apply plugin: 'com.google.gms.google-services'
android { android {
compileSdkVersion 31 compileSdkVersion 31
buildToolsVersion "30.0.3" buildToolsVersion "30.0.3"
...@@ -33,6 +34,7 @@ dependencies { ...@@ -33,6 +34,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.4.0' implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0' implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2' implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'com.google.firebase:firebase-storage:19.1.1'
testImplementation 'junit:junit:4.+' testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
...@@ -44,5 +46,11 @@ dependencies { ...@@ -44,5 +46,11 @@ dependencies {
implementation 'com.opencsv:opencsv:4.6' // Here is opencsv library implementation 'com.opencsv:opencsv:4.6' // Here is opencsv library
implementation files('libs\\YouTubeAndroidPlayerApi.jar')
implementation platform('com.google.firebase:firebase-bom:29.3.1')
implementation 'com.google.firebase:firebase-auth'
} }
\ No newline at end of file
{
"project_info": {
"project_number": "642347843728",
"project_id": "attention-assessment",
"storage_bucket": "attention-assessment.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:642347843728:android:c7e91fc87a80c3a5b61815",
"android_client_info": {
"package_name": "com.anuththara18.attentionassessment"
}
},
"oauth_client": [
{
"client_id": "642347843728-u7co8a3vsktblmr57r5r6ees4uof65d4.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyDth7XK-DMLvkNCziMz55eQkSuNCPzWsZk"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "642347843728-u7co8a3vsktblmr57r5r6ees4uof65d4.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
\ No newline at end of file
...@@ -105,7 +105,7 @@ public class ParentDetailsActivity extends AppCompatActivity { ...@@ -105,7 +105,7 @@ public class ParentDetailsActivity extends AppCompatActivity {
} }
else{ else{
diagnosis = (String) genderradioButton.getText(); diagnosis = (String) genderradioButton.getText();
Toast.makeText(ParentDetailsActivity.this,genderradioButton.getText(), Toast.LENGTH_SHORT).show(); //Toast.makeText(ParentDetailsActivity.this,genderradioButton.getText(), Toast.LENGTH_SHORT).show();
nav = 1; nav = 1;
if (LanguageActivity.text.equals("English")) { if (LanguageActivity.text.equals("English")) {
startActivity(new Intent(ParentDetailsActivity.this, ConsentFormActivity.class)); startActivity(new Intent(ParentDetailsActivity.this, ConsentFormActivity.class));
......
...@@ -36,6 +36,12 @@ import com.anuththara18.attentionassessment.details.ParentDetailsActivity; ...@@ -36,6 +36,12 @@ import com.anuththara18.attentionassessment.details.ParentDetailsActivity;
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.selective.Selective; import com.anuththara18.attentionassessment.selective.Selective;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.OnProgressListener;
import com.google.firebase.storage.StorageReference;
import com.google.firebase.storage.UploadTask;
import com.opencsv.CSVWriter; import com.opencsv.CSVWriter;
import java.io.File; import java.io.File;
...@@ -56,6 +62,8 @@ public class FACompleteScreen extends AppCompatActivity { ...@@ -56,6 +62,8 @@ public class FACompleteScreen extends AppCompatActivity {
List<Focused> dataList; List<Focused> dataList;
SQLiteDatabase mDatabase; SQLiteDatabase mDatabase;
String csv;
// declaring width and height // declaring width and height
// for our PDF file. // for our PDF file.
int pageHeight = 1520; int pageHeight = 1520;
...@@ -161,7 +169,7 @@ public class FACompleteScreen extends AppCompatActivity { ...@@ -161,7 +169,7 @@ public class FACompleteScreen extends AppCompatActivity {
/*******************************************************************************************/ /*******************************************************************************************/
String csv = (Environment.getExternalStorageDirectory().getAbsolutePath() + "/FocusedAttention.csv"); // Here csv file name is MyCsvFile.csv csv = (Environment.getExternalStorageDirectory().getAbsolutePath() + "/FocusedAttention.csv"); // Here csv file name is MyCsvFile.csv
// csv will create inside phone storage. // csv will create inside phone storage.
CSVWriter writer = null; CSVWriter writer = null;
...@@ -337,6 +345,33 @@ public class FACompleteScreen extends AppCompatActivity { ...@@ -337,6 +345,33 @@ public class FACompleteScreen extends AppCompatActivity {
} }
public void uploadToFirebase() {
FirebaseAuth auth = FirebaseAuth.getInstance();
if ( auth.getCurrentUser().getUid() == null ) {
auth.signInAnonymously();
}
StorageReference storageRef = FirebaseStorage.getInstance().getReference();
Uri file = Uri.fromFile(new File(csv));
StorageReference storageReference = storageRef.child(auth.getCurrentUser().getUid() + file.getLastPathSegment());
storageReference.putFile(file).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
@Override
public void onProgress(@NonNull UploadTask.TaskSnapshot snapshot) {
//Toast.makeText(getApplicationContext(), "Upload Filed", Toast.LENGTH_SHORT).show();
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(getApplicationContext(), "Upload successful", Toast.LENGTH_SHORT).show();
}
});
}
/**************************************************************************************************/ /**************************************************************************************************/
......
...@@ -83,7 +83,7 @@ public class FocusedAttentionGame1 extends AppCompatActivity { ...@@ -83,7 +83,7 @@ public class FocusedAttentionGame1 extends AppCompatActivity {
Integer[] isi = { 3000, 3500, 4000, 4500, 5000, 5500, 6000 }; Integer[] isi = { 3000, 3500, 4000, 4500, 5000, 5500, 6000 };
Integer[] images = {R.drawable.monkey, R.drawable.baby_zebra, R.drawable.elephant, R.drawable.pig, R.drawable.giraffe, Integer[] images = {R.drawable.monkey, R.drawable.baby_zebra, R.drawable.elephant, R.drawable.pig, R.drawable.giraffe,
R.drawable.cow, R.drawable.horse, R.drawable.dino, R.drawable.lion, R.drawable.dog}; R.drawable.cow, R.drawable.horse, R.drawable.dino, R.drawable.lion, R.drawable.dog};
MediaPlayer mp, mp2; MediaPlayer mp, mp2;
...@@ -407,42 +407,42 @@ public class FocusedAttentionGame1 extends AppCompatActivity { ...@@ -407,42 +407,42 @@ public class FocusedAttentionGame1 extends AppCompatActivity {
imageView.setOnClickListener(new View.OnClickListener() { imageView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
mp2 = MediaPlayer.create(getApplicationContext(), R.raw.button_click); mp2 = MediaPlayer.create(getApplicationContext(), R.raw.button_click);
mp2.start(); mp2.start();
// Your action here on button click // Your action here on button click
clickedTime = System.currentTimeMillis(); clickedTime = System.currentTimeMillis();
reactionTime = (clickedTime - startTime); reactionTime = (clickedTime - startTime);
//if (clicked.equals("monkey")) { //if (clicked.equals("monkey")) {
if ( i - 1 == 2 || i - 1 == 14 || i - 1 == 26 || i - 1 == 38 ) { if ( i - 1 == 2 || i - 1 == 14 || i - 1 == 26 || i - 1 == 38 ) {
totalReactionTime = totalReactionTime + reactionTime; totalReactionTime = totalReactionTime + reactionTime;
Log.d("correct ", startTime + " " + clickedTime + " " + reactionTime); Log.d("correct ", startTime + " " + clickedTime + " " + reactionTime);
noOfCorrectResponses++; noOfCorrectResponses++;
imageView.setEnabled(false); imageView.setEnabled(false);
} else { } else {
Log.d("wrong", startTime + " " + clickedTime + " " + reactionTime); Log.d("wrong", startTime + " " + clickedTime + " " + reactionTime);
noOfCommissionErrors++; noOfCommissionErrors++;
} }
} }
}); });
imageView2.setOnClickListener(new View.OnClickListener() { imageView2.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
mp2 = MediaPlayer.create(getApplicationContext(), R.raw.button_click); mp2 = MediaPlayer.create(getApplicationContext(), R.raw.button_click);
mp2.start(); mp2.start();
// Your action here on button click // Your action here on button click
clickedTime = System.currentTimeMillis(); clickedTime = System.currentTimeMillis();
reactionTime = (clickedTime - startTime); reactionTime = (clickedTime - startTime);
//if (clicked.equals("monkey")) { //if (clicked.equals("monkey")) {
if ( i - 1 == 4 || i - 1 == 16 || i - 1 == 28 || i - 1 == 40 ) { if ( i - 1 == 4 || i - 1 == 16 || i - 1 == 28 || i - 1 == 40 ) {
totalReactionTime = totalReactionTime + reactionTime; totalReactionTime = totalReactionTime + reactionTime;
Log.d("correct ", startTime + " " + clickedTime + " " + reactionTime); Log.d("correct ", startTime + " " + clickedTime + " " + reactionTime);
noOfCorrectResponses++; noOfCorrectResponses++;
imageView2.setEnabled(false); imageView2.setEnabled(false);
} else { } else {
Log.d("wrong", startTime + " " + clickedTime + " " + reactionTime); Log.d("wrong", startTime + " " + clickedTime + " " + reactionTime);
noOfCommissionErrors++; noOfCommissionErrors++;
} }
} }
}); });
...@@ -450,20 +450,20 @@ public class FocusedAttentionGame1 extends AppCompatActivity { ...@@ -450,20 +450,20 @@ public class FocusedAttentionGame1 extends AppCompatActivity {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
mp2 = MediaPlayer.create(getApplicationContext(), R.raw.button_click); mp2 = MediaPlayer.create(getApplicationContext(), R.raw.button_click);
mp2.start(); mp2.start();
// Your action here on button click // Your action here on button click
clickedTime = System.currentTimeMillis(); clickedTime = System.currentTimeMillis();
reactionTime = (clickedTime - startTime); reactionTime = (clickedTime - startTime);
if ( i - 1 == 6 || i - 1 == 18 || i - 1 == 30 ) { if ( i - 1 == 6 || i - 1 == 18 || i - 1 == 30 ) {
totalReactionTime = totalReactionTime + reactionTime; totalReactionTime = totalReactionTime + reactionTime;
Log.d("correct ", startTime + " " + clickedTime + " " + reactionTime); Log.d("correct ", startTime + " " + clickedTime + " " + reactionTime);
noOfCorrectResponses++; noOfCorrectResponses++;
imageView3.setEnabled(false); imageView3.setEnabled(false);
} else { } else {
Log.d("wrong", startTime + " " + clickedTime + " " + reactionTime); Log.d("wrong", startTime + " " + clickedTime + " " + reactionTime);
noOfCommissionErrors++; noOfCommissionErrors++;
} }
} }
}); });
...@@ -472,20 +472,20 @@ public class FocusedAttentionGame1 extends AppCompatActivity { ...@@ -472,20 +472,20 @@ public class FocusedAttentionGame1 extends AppCompatActivity {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
mp2 = MediaPlayer.create(getApplicationContext(), R.raw.button_click); mp2 = MediaPlayer.create(getApplicationContext(), R.raw.button_click);
mp2.start(); mp2.start();
// Your action here on button click // Your action here on button click
clickedTime = System.currentTimeMillis(); clickedTime = System.currentTimeMillis();
reactionTime = (clickedTime - startTime); reactionTime = (clickedTime - startTime);
if ( i - 1 == 8 || i - 1 == 20 || i - 1 == 32 ) { if ( i - 1 == 8 || i - 1 == 20 || i - 1 == 32 ) {
totalReactionTime = totalReactionTime + reactionTime; totalReactionTime = totalReactionTime + reactionTime;
Log.d("correct ", startTime + " " + clickedTime + " " + reactionTime); Log.d("correct ", startTime + " " + clickedTime + " " + reactionTime);
noOfCorrectResponses++; noOfCorrectResponses++;
imageView4.setEnabled(false); imageView4.setEnabled(false);
} else { } else {
Log.d("wrong", startTime + " " + clickedTime + " " + reactionTime); Log.d("wrong", startTime + " " + clickedTime + " " + reactionTime);
noOfCommissionErrors++; noOfCommissionErrors++;
} }
} }
}); });
...@@ -494,20 +494,20 @@ public class FocusedAttentionGame1 extends AppCompatActivity { ...@@ -494,20 +494,20 @@ public class FocusedAttentionGame1 extends AppCompatActivity {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
mp2 = MediaPlayer.create(getApplicationContext(), R.raw.button_click); mp2 = MediaPlayer.create(getApplicationContext(), R.raw.button_click);
mp2.start(); mp2.start();
// Your action here on button click // Your action here on button click
clickedTime = System.currentTimeMillis(); clickedTime = System.currentTimeMillis();
reactionTime = (clickedTime - startTime); reactionTime = (clickedTime - startTime);
if ( i - 1 == 10 || i - 1 == 22 || i - 1 == 34 ) { if ( i - 1 == 10 || i - 1 == 22 || i - 1 == 34 ) {
totalReactionTime = totalReactionTime + reactionTime; totalReactionTime = totalReactionTime + reactionTime;
Log.d("correct ", startTime + " " + clickedTime + " " + reactionTime); Log.d("correct ", startTime + " " + clickedTime + " " + reactionTime);
noOfCorrectResponses++; noOfCorrectResponses++;
imageView5.setEnabled(false); imageView5.setEnabled(false);
} else { } else {
Log.d("wrong", startTime + " " + clickedTime + " " + reactionTime); Log.d("wrong", startTime + " " + clickedTime + " " + reactionTime);
noOfCommissionErrors++; noOfCommissionErrors++;
} }
} }
}); });
...@@ -516,20 +516,20 @@ public class FocusedAttentionGame1 extends AppCompatActivity { ...@@ -516,20 +516,20 @@ public class FocusedAttentionGame1 extends AppCompatActivity {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
mp2 = MediaPlayer.create(getApplicationContext(), R.raw.button_click); mp2 = MediaPlayer.create(getApplicationContext(), R.raw.button_click);
mp2.start(); mp2.start();
// Your action here on button click // Your action here on button click
clickedTime = System.currentTimeMillis(); clickedTime = System.currentTimeMillis();
reactionTime = (clickedTime - startTime); reactionTime = (clickedTime - startTime);
if ( i - 1 == 12 || i - 1 == 24 || i - 1 == 36 ) { if ( i - 1 == 12 || i - 1 == 24 || i - 1 == 36 ) {
totalReactionTime = totalReactionTime + reactionTime; totalReactionTime = totalReactionTime + reactionTime;
Log.d("correct ", startTime + " " + clickedTime + " " + reactionTime); Log.d("correct ", startTime + " " + clickedTime + " " + reactionTime);
noOfCorrectResponses++; noOfCorrectResponses++;
imageView6.setEnabled(false); imageView6.setEnabled(false);
} else { } else {
Log.d("wrong", startTime + " " + clickedTime + " " + reactionTime); Log.d("wrong", startTime + " " + clickedTime + " " + reactionTime);
noOfCommissionErrors++; noOfCommissionErrors++;
} }
} }
}); });
......
...@@ -35,6 +35,15 @@ import com.anuththara18.attentionassessment.consentform.ParentsConsentDatabaseHe ...@@ -35,6 +35,15 @@ import com.anuththara18.attentionassessment.consentform.ParentsConsentDatabaseHe
import com.anuththara18.attentionassessment.details.ParentDetailsActivity; import com.anuththara18.attentionassessment.details.ParentDetailsActivity;
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.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.OnProgressListener;
import com.google.firebase.storage.StorageReference;
import com.google.firebase.storage.UploadTask;
import com.opencsv.CSVWriter; import com.opencsv.CSVWriter;
import java.io.File; import java.io.File;
...@@ -196,6 +205,8 @@ public class SelectiveACompleteScreen extends AppCompatActivity { ...@@ -196,6 +205,8 @@ public class SelectiveACompleteScreen extends AppCompatActivity {
e.printStackTrace(); e.printStackTrace();
} }
uploadToFirebase(csv);
/*******************************************************************************************/ /*******************************************************************************************/
PdfDocument pdfDocument = new PdfDocument(); PdfDocument pdfDocument = new PdfDocument();
...@@ -343,4 +354,35 @@ public class SelectiveACompleteScreen extends AppCompatActivity { ...@@ -343,4 +354,35 @@ public class SelectiveACompleteScreen extends AppCompatActivity {
return scaledBitmap; return scaledBitmap;
} }
public void uploadToFirebase(String csv) {
FirebaseAuth auth = FirebaseAuth.getInstance();
if ( auth.getCurrentUser() == null ) {
auth.signInAnonymously().addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.i("test user", String.valueOf(task.isSuccessful()));
}
});
}
StorageReference storageRef = FirebaseStorage.getInstance().getReference();
Uri file = Uri.fromFile(new File(csv));
StorageReference storageReference = storageRef.child(auth.getCurrentUser().getUid() + "/Game1/" + file.getLastPathSegment());
storageReference.putFile(file).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
@Override
public void onProgress(@NonNull UploadTask.TaskSnapshot snapshot) {
//Toast.makeText(getApplicationContext(), "Upload Filed", Toast.LENGTH_SHORT).show();
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(getApplicationContext(), "Upload successful", Toast.LENGTH_SHORT).show();
}
});
}
} }
...@@ -5,8 +5,22 @@ ...@@ -5,8 +5,22 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"
android:background="@color/white"
tools:context=".videos.IntroductoryVideoPortraitActivity"> tools:context=".videos.IntroductoryVideoPortraitActivity">
<TextView
android:id="@+id/skip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:fontFamily="@font/poppins_medium"
android:gravity="center"
android:text="@string/skip"
android:textColor="@color/black"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<WebView android:id="@+id/videoView" <WebView android:id="@+id/videoView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
...@@ -14,4 +28,12 @@ ...@@ -14,4 +28,12 @@
android:layout_centerHorizontal="true"> android:layout_centerHorizontal="true">
</WebView> </WebView>
<!--
<com.google.android.youtube.player.YouTubePlayerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/ytPlayer"
app:layout_constraintTop_toTopOf="parent"/>
-->
</LinearLayout> </LinearLayout>
\ No newline at end of file
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
<string name="girl">ගැහැණු</string> <string name="girl">ගැහැණු</string>
<string name="boy">පිරිමි</string> <string name="boy">පිරිමි</string>
<string name="next">ඊළඟ</string> <string name="next">ඊළඟ</string>
<string name="skip">මඟ හැර යන්න...</string>
<string name="previous">පෙර</string> <string name="previous">පෙර</string>
<string name="age">ඔබේ දරුවාගේ වයස තෝරන්න:</string> <string name="age">ඔබේ දරුවාගේ වයස තෝරන්න:</string>
<string name="language">භාෂාව තෝරන්න:</string> <string name="language">භාෂාව තෝරන්න:</string>
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
<string name="girl">Girl</string> <string name="girl">Girl</string>
<string name="boy">Boy</string> <string name="boy">Boy</string>
<string name="next">Next</string> <string name="next">Next</string>
<string name="skip">Skip...</string>
<string name="previous">Previous</string> <string name="previous">Previous</string>
<string name="age">Select your child\'s age:</string> <string name="age">Select your child\'s age:</string>
<string name="language">Select language:</string> <string name="language">Select language:</string>
......
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