diff --git a/app/build.gradle b/app/build.gradle
index 42f7aa5..2d6d6e2 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -40,4 +40,13 @@ dependencies {
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
+ implementation fileTree(include: ['*.jar'], dir: 'libs')
+ implementation 'org.json:json:20180813'
+ implementation 'org.apache.commons:commons-lang3:3.8.1'
+ implementation 'org.apache.commons:commons-text:1.6'
+ implementation 'org.apache.commons:commons-collections4:4.4'
+ implementation 'org.apache.commons:commons-lang3:3.9'
+ implementation 'org.apache.commons:commons-lang3:3.12.0'
+
+
}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index a5fd4e3..98303ab 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -30,6 +30,9 @@
+
diff --git a/app/src/main/java/com/example/snackscan/MainActivity.java b/app/src/main/java/com/example/snackscan/MainActivity.java
index c1323ac..5bc6701 100644
--- a/app/src/main/java/com/example/snackscan/MainActivity.java
+++ b/app/src/main/java/com/example/snackscan/MainActivity.java
@@ -41,6 +41,7 @@ public class MainActivity extends AppCompatActivity {
private ImageView iview;
private Button btn;
private Button nextBtn;
+ private Button manualBtn;
private String fileName = "";
private Button CaptureImageBtn,detectTextBtn;
private ImageView imageView;
@@ -54,12 +55,12 @@ protected void onCreate(Bundle savedInstanceState) {
iview = (ImageView) findViewById(R.id.imageview);
btn = (Button) findViewById(R.id.button);
nextBtn = (Button) findViewById(R.id.nextBtn);
-
+ manualBtn = (Button) findViewById(R.id.manualBtn);
nextBtn.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
- System.out.println("Button working");
+
Intent sendText = new Intent(getApplicationContext(), TextRecognitionActivity.class);
sendText.putExtra("scanned_text", resultText);
startActivity(sendText);
@@ -68,6 +69,7 @@ public void onClick(View v){
}
});
+
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -80,6 +82,14 @@ public void onClick(View v) {
}
});
+
+ manualBtn.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ startActivity(new Intent(getApplicationContext(), ManualInputActivity.class));
+ finish();
+ }
+ });
}
public void logout(View view) {
diff --git a/app/src/main/java/com/example/snackscan/ManualInputActivity.java b/app/src/main/java/com/example/snackscan/ManualInputActivity.java
new file mode 100644
index 0000000..55573d7
--- /dev/null
+++ b/app/src/main/java/com/example/snackscan/ManualInputActivity.java
@@ -0,0 +1,82 @@
+package com.example.snackscan;
+
+import static android.content.ContentValues.TAG;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.ImageView;
+import android.widget.TextView;
+import android.widget.Toast;
+import androidx.appcompat.app.AppCompatActivity;
+
+import com.google.android.gms.tasks.OnSuccessListener;
+import com.google.firebase.auth.FirebaseAuth;
+import com.google.firebase.firestore.DocumentReference;
+import com.google.firebase.firestore.FirebaseFirestore;
+
+public class ManualInputActivity extends AppCompatActivity {
+ EditText mCal, mCarb, mFat, mProtein;
+ Button mSubmit;
+ FirebaseAuth fAuth;
+ FirebaseFirestore fStore;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_manual_input);
+ // TODOļ¼ add 4 elements, click submit btn then upload to the user db to firebase
+ mCal = findViewById(R.id.calMnumber);
+ mCarb = findViewById(R.id.carbMnumber);
+ mFat = findViewById(R.id.fatMnumber);
+ mProtein = findViewById(R.id.proteinMnumber);
+ mSubmit = (Button) findViewById(R.id.submitButton);
+ fStore = FirebaseFirestore.getInstance();
+ fAuth = FirebaseAuth.getInstance();
+
+ mSubmit.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Intent intent = getIntent();
+ String id = intent.getStringExtra("user_id");
+ String cal = mCal.getText().toString();
+ String carb = mCarb.getText().toString();
+ String fat = mFat.getText().toString();
+ String protein = mProtein.getText().toString();
+ String uid = fAuth.getCurrentUser().getUid();
+
+ DocumentReference documentReference = fStore.collection("users").document(uid);
+ documentReference.update("Calories", cal).addOnSuccessListener(new OnSuccessListener() {
+ @Override
+ public void onSuccess(Void unused) {
+ Log.d(TAG, "onSuccess: user calories added for " + uid);
+ }
+ });
+ documentReference.update("Carbs", carb).addOnSuccessListener(new OnSuccessListener() {
+ @Override
+ public void onSuccess(Void unused) {
+ Log.d(TAG, "onSuccess: user carbs added for " + uid);
+ }
+ });
+ documentReference.update("Fat", fat).addOnSuccessListener(new OnSuccessListener() {
+ @Override
+ public void onSuccess(Void unused) {
+ Log.d(TAG, "onSuccess: user fat added for " + uid);
+ }
+ });
+ documentReference.update("Proteins", protein).addOnSuccessListener(new OnSuccessListener() {
+ @Override
+ public void onSuccess(Void unused) {
+ Log.d(TAG, "onSuccess: user proteins added for " + uid);
+ }
+ });
+ Toast.makeText(getApplicationContext(),"Inserted Successfully",Toast.LENGTH_LONG).show();
+ startActivity(new Intent(getApplicationContext(), MainActivity.class));
+ finish();
+ }
+ });
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/snackscan/TextRecognitionActivity.java b/app/src/main/java/com/example/snackscan/TextRecognitionActivity.java
index 8f47538..d664aaa 100644
--- a/app/src/main/java/com/example/snackscan/TextRecognitionActivity.java
+++ b/app/src/main/java/com/example/snackscan/TextRecognitionActivity.java
@@ -1,6 +1,11 @@
package com.example.snackscan;
+//package org.apache.commons.text.similarity;
import androidx.appcompat.app.AppCompatActivity;
+import org.apache.commons.text.similarity.CosineDistance;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.Arrays;
import android.content.Intent;
import android.os.Bundle;
@@ -8,20 +13,103 @@
public class TextRecognitionActivity extends AppCompatActivity {
TextView Ingredients;
+ TextView Calories;
+ TextView Protein;
+ TextView Carb;
+ TextView Fat;
+ private int caloriesIndex;
+ private int proteinIndex;
+ private int carbIndex;
+ private int fatIndex;
+ private Boolean foundCal=false;
+ private Boolean foundProtein=false;
+ private Boolean foundCarb =false;
+ private Boolean foundFat=false;
+
+ public static double findSimilarity(String x, String y) {
+
+ double maxLength = Math.max(x.length(), y.length());
+ if (maxLength > 0) {
+ // optionally ignore case if needed
+ return (maxLength - StringUtils.getLevenshteinDistance(x, y)) / maxLength;
+ }
+ return 1.0;
+ }
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_text_recognition);
+// Ingredients = (TextView)findViewById(R.id.ingredients);
+ Calories = (TextView)findViewById((R.id.calnumber));
+ Protein = (TextView)findViewById(R.id.proteinnumber);
+ Carb = (TextView)findViewById((R.id.carbnumber));
+ Fat = (TextView)findViewById(R.id.fatnumber);
+
+
+
+
+
+ // Function to get similarity
- Ingredients = (TextView)findViewById(R.id.ingredients);
Intent intent = getIntent();
String id = intent.getStringExtra("scanned_text");
- Ingredients.setText(id);
- System.out.println(id);
+ id.replace("\n", " ");
+ String [] food_info = id.split("\\s+");
+ //String [] food_info = {"CElurios", "560", "prOton", "34","fut", "23", "Sagar","9859"};
+
+ System.out.println("TESTING!!!!!!!");
+// System.out.println(food_info.length);
+// System.out.println();
+
+ for(int i=0; i< food_info.length; i++){
+ if(findSimilarity("calories", food_info[i].toLowerCase())>= 0.5 && !foundCal){
+
+ caloriesIndex = i+1;
+ foundCal = true;
+ }
+ if(findSimilarity("protein", food_info[i].toLowerCase())>= 0.5 && !foundProtein){
+
+ proteinIndex = i+1;
+ foundProtein = true;
+
+ }
+ if(findSimilarity("carbohydrates", food_info[i].toLowerCase())>= 0.5 && !foundCarb){
+
+ carbIndex = i+1;
+ foundCarb = true;
+
+ }
+ if(findSimilarity("fat", food_info[i].toLowerCase())>= 0.8 && !foundFat){
+
+ fatIndex = i+1;
+ foundFat = true;
+
+ }
+
+ }
+ System.out.println(caloriesIndex);
+ System.out.println(proteinIndex);
+ System.out.println(carbIndex);
+ System.out.println(fatIndex);
+
+ System.out.println(Arrays.deepToString(food_info));
+// System.out.println("printing Array of food");
+
+ Calories.setText(food_info[caloriesIndex]);
+ Protein.setText(food_info[proteinIndex]);
+ Carb.setText(food_info[carbIndex]);
+ Fat.setText(food_info[fatIndex]);
+ //Ingredients.setText(id);
+
+
+
+ //System.out.println(Arrays.deepToString(food_info));
+
+
}
}
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_manual_input.xml b/app/src/main/res/layout/activity_manual_input.xml
new file mode 100644
index 0000000..12ac86e
--- /dev/null
+++ b/app/src/main/res/layout/activity_manual_input.xml
@@ -0,0 +1,189 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_text_recognition.xml b/app/src/main/res/layout/activity_text_recognition.xml
index 39c010f..0d3140d 100644
--- a/app/src/main/res/layout/activity_text_recognition.xml
+++ b/app/src/main/res/layout/activity_text_recognition.xml
@@ -41,7 +41,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/ubuntu_mono_bold"
- android:text="1500"
+ android:text=""
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
android:textSize="18dp"
app:layout_constraintBottom_toBottomOf="parent"
@@ -82,7 +82,7 @@
app:layout_constraintVertical_bias="0.405" />
-
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/camera_page.xml b/app/src/main/res/layout/camera_page.xml
index 1ed19c0..7486ddd 100644
--- a/app/src/main/res/layout/camera_page.xml
+++ b/app/src/main/res/layout/camera_page.xml
@@ -28,11 +28,25 @@
android:text="Camera"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintHorizontal_bias="0.178"
+ app:layout_constraintHorizontal_bias="0.1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageview"
app:layout_constraintVertical_bias="0.84" />
+
+