Commit 9e2c417e authored by Pyone Thant Win's avatar Pyone Thant Win
Browse files

v 0.1

parent c385d98d
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
......@@ -18,18 +18,22 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".side_ruler"></activity>
<activity android:name=".top_ruler"></activity>
<activity android:name=".import_picture2" />
<activity android:name=".side_ruler" />
<activity android:name=".import_pictures" />
<activity android:name=".export_data" />
<activity android:name=".foodInfo" />
<activity android:name=".login" />
<activity android:name=".MainActivity">
<activity android:name=".export_data">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".foodInfo" />
<activity android:name=".login" />
<activity android:name=".MainActivity">
</activity>
</application>
</manifest>
\ No newline at end of file
......@@ -6,6 +6,7 @@ import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class database_helper extends SQLiteOpenHelper{
public static final String DATABASE_NAME="calories.db";
public static final String TABLE_NAME="credentials";
public static final String COL_1="ID";
......
......@@ -31,16 +31,22 @@ public class export_data extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_export_data);
_txt_fruitName = (EditText)findViewById(R.id.txt_fruitName);
_btn_next = (Button)findViewById(R.id.btn_next);
//final String fruit = _txt_fruitName.getText().toString();
//final String _fruit = fruit.substring(0, 1).toUpperCase() + fruit.substring(1);
_btn_next = (Button)findViewById(R.id._btn_SideView);
_btn_next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
fr_density = getCSVDATA(_txt_fruitName.getText().toString());
if (fr_density != 0){
String fruit = _txt_fruitName.getText().toString();
fruit = fruit.substring(0, 1).toUpperCase() + fruit.substring(1);
Intent intent = new Intent(export_data.this, import_pictures.class);
intent.putExtra("density", fr_density);
intent.putExtra("Fruit", fruit);
startActivity(intent);
} else {
//Toast.makeText(getApplicationContext(), _txt_fruitName.getText().toString(), Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "Sorry, the fruit is not in our database yet. Please put another fruit.", Toast.LENGTH_SHORT).show();
}
}
......
......@@ -2,6 +2,7 @@ package com.example.calorieestimator;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
......@@ -20,77 +21,90 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Arrays;
import java.math.BigDecimal;
public class foodInfo extends AppCompatActivity {
TextView _api_result, _textv2_density;
TextView _api_result, _title;
EditText _food_name;
Button _btn_calc;
Button _btn_calc, _btn_start;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_food_info);
Double density = getIntent().getExtras().getDouble("density");
final String fruit = getIntent().getExtras().getString("Fruit");
final Double mass = getIntent().getExtras().getDouble("mass");
_api_result = (TextView)findViewById(R.id.api_view);
_textv2_density = (TextView)findViewById(R.id.textView_density);
_food_name = (EditText)findViewById(R.id.food_name);
_title = (TextView)findViewById(R.id.textView_title);
_btn_start = (Button)findViewById(R.id.btn_start);
_btn_calc = (Button)findViewById(R.id.btn_calc);
_textv2_density.setText(density.toString());
_title.setText("Total Calories of "+ fruit + " is:");
_btn_calc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String food = _food_name.getText().toString();
String[] t = food.split(" ", 0);
String food = fruit;
String[] t = food.split(" ", 0);
String api_helper = "";
int len = t.length;
for (int i=0; i<len; i++){
api_helper = api_helper + t[i]+ "%20";
}
api_helper = api_helper + "Raw";
//Log.d("Result: ", api_helper);
String URL1 = "https://api.nal.usda.gov/fdc/v1/foods/search?api_key=KEVJZOV5r0tWduJkb2efmIX5hsp78tjCggR4jdBY&query=";
String URL = URL1 + api_helper;
RequestQueue requestQueue = Volley.newRequestQueue(foodInfo.this);
JsonObjectRequest objectRequest = new JsonObjectRequest(
Request.Method.GET,
URL,
null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try{
JSONArray jsonArray = response.getJSONArray("foods");
String api_helper = "";
int len = t.length;
for (int i=0; i<len; i++){
api_helper = api_helper + t[i]+ "%20";
}
api_helper = api_helper + "Raw";
//Log.d("Result: ", api_helper);
JSONObject food = jsonArray.getJSONObject(0);
String description = food.getString("description");
JSONArray foodNutrients = food.getJSONArray("foodNutrients");
JSONObject nutrients = foodNutrients.getJSONObject(3);
String amount = nutrients.getString("nutrientNumber");
String kcal = nutrients.getString("unitName");
String final_str = description + ": " + amount + kcal;
String URL1 = "https://api.nal.usda.gov/fdc/v1/foods/search?api_key=KEVJZOV5r0tWduJkb2efmIX5hsp78tjCggR4jdBY&query=";
String URL = URL1 + api_helper;
RequestQueue requestQueue = Volley.newRequestQueue(foodInfo.this);
JsonObjectRequest objectRequest = new JsonObjectRequest(
Request.Method.GET,
URL,
null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try{
JSONArray jsonArray = response.getJSONArray("foods");
JSONObject food = jsonArray.getJSONObject(0);
String description = food.getString("description");
JSONArray foodNutrients = food.getJSONArray("foodNutrients");
JSONObject nutrients = foodNutrients.getJSONObject(3);
String amount = nutrients.getString("nutrientNumber");
Double _amount = Double.parseDouble(amount);
_amount = _amount/100 * mass;
BigDecimal bd = BigDecimal.valueOf(_amount);
bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
_amount = bd.doubleValue();
amount = _amount.toString();
String kcal = nutrients.getString("unitName");
String final_str = amount + kcal;
_api_result.setText(final_str.toString());
//Log.e("Rest Response", response.toString());
} catch (JSONException e){
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("Error Response", error.toString());
_api_result.setText(final_str.toString());
//Log.e("Rest Response", response.toString());
} catch (JSONException e){
e.printStackTrace();
}
}
);
requestQueue.add(objectRequest);
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("Error Response", error.toString());
}
}
);
requestQueue.add(objectRequest);
}
});
_btn_start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(foodInfo.this, export_data.class);
startActivity(intent);
}
});
}
}
package com.example.calorieestimator;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.media.ExifInterface;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
import com.squareup.picasso.Picasso;
import java.io.IOException;
import java.io.InputStream;
public class import_picture2 extends AppCompatActivity {
ImageView top, ruler;
Button gallery, to_topRuler;
private static final int IMAGE_PICK_CODE=1000;
private static final int PERMISSION_CODE=1001;
String focal_length;
String pathStr;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_import_picture2);
final Double density = getIntent().getExtras().getDouble("Density");
final String fruit = getIntent().getExtras().getString("Fruit");
final Double _real_width = getIntent().getExtras().getDouble("RealWidth");
final Double _real_height = getIntent().getExtras().getDouble("RealHeight");
top = (ImageView)findViewById(R.id.imageView_top);
ruler = (ImageView)findViewById(R.id.imageView_ruler);
gallery = (Button)findViewById(R.id.btn_gallery);
to_topRuler = (Button)findViewById(R.id._btn_TopRuler);
final String ruler_URL = "https://catchydesk.com/wp-content/uploads/2019/04/Inch-ruler-actual-size.png";
gallery.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Toast.makeText(getApplicationContext(), "Gallery", Toast.LENGTH_SHORT).show();
openGallery();
Picasso.get().load(ruler_URL).into(ruler);
}
});
to_topRuler.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Toast.makeText(getApplicationContext(), focal_length, Toast.LENGTH_SHORT).show();
if (pathStr==""){
Toast.makeText(getApplicationContext(), "Please select a picture", Toast.LENGTH_SHORT).show();
} else {
//Toast.makeText(getApplicationContext(), focal_length + density.toString(), Toast.LENGTH_SHORT).show();
Intent intent = new Intent(import_picture2.this, top_ruler.class);
intent.putExtra("Focal_length2", Integer.valueOf(focal_length));
intent.putExtra("Density", density);
intent.putExtra("Fruit", fruit);
intent.putExtra("RealWidth", _real_width);
intent.putExtra("RealHeight", _real_height);
startActivity(intent);
}
}
});
}
private void openGallery(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED){
String[] permissions = {Manifest.permission.READ_EXTERNAL_STORAGE};
requestPermissions(permissions, PERMISSION_CODE);
} else {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, IMAGE_PICK_CODE);
}
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode) {
case PERMISSION_CODE:{
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED){
openGallery();
} else {
Toast.makeText(this, "Permission Denied. Required to grant access.", Toast.LENGTH_SHORT).show();
}
}
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
//String path = "";
if (resultCode == RESULT_OK && requestCode == IMAGE_PICK_CODE){
Uri path = data.getData();
pathStr = data.getData().getPath();
top.setImageURI(data.getData());
try{
InputStream in = getContentResolver().openInputStream(path);
ExifInterface exif = new ExifInterface(in);
focal_length= exif.getAttribute(ExifInterface.TAG_FOCAL_LENGTH);
focal_length = focal_length.split("/", 2)[0];
} catch (IOException e){
e.printStackTrace();
}
}
}
}
......@@ -11,13 +11,10 @@ import android.media.ExifInterface;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.util.Log;
import android.util.Rational;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.squareup.picasso.Picasso;
......@@ -27,7 +24,7 @@ import java.io.InputStream;
public class import_pictures extends AppCompatActivity {
Button _get_side, _btn_next;
Button _get_side, to_side;
ImageView _side_view, _ruler;
private static final int IMAGE_PICK_CODE=1000;
private static final int PERMISSION_CODE=1001;
......@@ -38,12 +35,12 @@ public class import_pictures extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_import_pictures);
final Double density = getIntent().getExtras().getDouble("density");
final String fruit = getIntent().getExtras().getString("Fruit");
_get_side = (Button)findViewById(R.id.btn_getSide);
_btn_next = (Button)findViewById(R.id.btn_next);
to_side = (Button)findViewById(R.id._btn_toSideRuler);
_side_view = (ImageView)findViewById(R.id.imageView_side);
_ruler = (ImageView)findViewById(R.id.imageView_ruler);
final String ruler_URL = "https://lh3.googleusercontent.com/proxy/8DtFyFkBz3Dzyt8cr8x7JGh2X5WAgQGC3rXn9gLwO0tDKGFBM7TXAoFZXiM0YrcAd4iHcEagGZU0q0iX7DW93i5OndoN-66v";
final String ruler_URL = "https://catchydesk.com/wp-content/uploads/2019/04/Inch-ruler-actual-size.png";
_get_side.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
......@@ -51,16 +48,18 @@ public class import_pictures extends AppCompatActivity {
openGallery();
}
});
_btn_next.setOnClickListener(new View.OnClickListener() {
to_side.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Toast.makeText(getApplicationContext(), focal_length, Toast.LENGTH_SHORT).show();
if (pathStr == ""){
if (pathStr==""){
Toast.makeText(getApplicationContext(), "Please select a picture", Toast.LENGTH_SHORT).show();
} else {
//Toast.makeText(getApplicationContext(), focal_length + density.toString(), Toast.LENGTH_SHORT).show();
Intent intent = new Intent(import_pictures.this, side_ruler.class);
intent.getIntExtra("Focal_length", Integer.valueOf(focal_length));
intent.getDoubleExtra("density", density);
intent.putExtra("Focal_length", Integer.valueOf(focal_length));
intent.putExtra("density", density);
intent.putExtra("Fruit", fruit);
startActivity(intent);
}
......@@ -110,11 +109,8 @@ public class import_pictures extends AppCompatActivity {
focal_length= exif.getAttribute(ExifInterface.TAG_FOCAL_LENGTH);
focal_length = focal_length.split("/", 2)[0];
} catch (IOException e){
Log.e("ERRORRRRR", e.toString());
e.printStackTrace();
}
}
}
......
......@@ -2,28 +2,68 @@ package com.example.calorieestimator;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
public class side_ruler extends AppCompatActivity {
EditText width, height;
Button _btn_next;
Button to_topView;
Double _height = 0.0;
Double _width = 0.0;
Double real_width = 0.0;
Double real_height = 0.0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_side_ruler);
Integer focal_length = getIntent().getExtras().getInt("Focal_length");
Double density = getIntent().getExtras().getDouble("density");
final Integer focal_length = getIntent().getExtras().getInt("Focal_length");
final Double density = getIntent().getExtras().getDouble("density");
final String fruit = getIntent().getExtras().getString("Fruit");
width = (EditText)findViewById(R.id.width_text);
height = (EditText)findViewById(R.id.height_text);
Double real_width;
Double real_height;
to_topView = (Button)findViewById(R.id._btn_TopView);
to_topView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!"".equals(height.getText().toString())){
_height = Double.parseDouble(height.getText().toString());
if (_height > 0.0){
real_height = getValues(focal_length, _height);
}
}
if (!"".equals(width.getText().toString())){
_width = Double.parseDouble(width.getText().toString());
if (_width > 0.0){
real_width = getValues(focal_length, _width);
}
}
//Toast.makeText(getApplicationContext(), real_height.toString() + " " + real_width.toString(), Toast.LENGTH_SHORT).show();
if (real_width > 0.0 && real_height > 0.0){
Intent intent = new Intent(side_ruler.this, import_picture2.class);
intent.putExtra("Density", density);
intent.putExtra("Fruit", fruit);
intent.putExtra("RealWidth", real_width);
intent.putExtra("RealHeight", real_height);
startActivity(intent);
}
else {
Toast.makeText(getApplicationContext(), "Please input both values", Toast.LENGTH_SHORT).show();
}
}
});
}
public Double getValues(Integer focalLength, Double sizeInImg) {
Double value;
value = (sizeInImg * 150) / ((focalLength/100)*2);
return value;
}
}
package com.example.calorieestimator;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import org.opencv.core.Mat;
public class top_ruler extends AppCompatActivity {
EditText heightText, widthText;
Button to_final;
Double height = 0.0;
Double width = 0.0;
Double real_width = 0.0;
Double real_height = 0.0;
Double mass = 0.0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_top_ruler);
final Double density = getIntent().getExtras().getDouble("Density");
final String fruit = getIntent().getExtras().getString("Fruit");
final Double _real_width = getIntent().getExtras().getDouble("RealWidth");
final Double _real_height = getIntent().getExtras().getDouble("RealHeight");
final Integer focal_length = getIntent().getExtras().getInt("Focal_length2");
widthText = (EditText)findViewById(R.id.top_width);
heightText= (EditText)findViewById(R.id.top_height);
to_final = (Button) findViewById(R.id.btn_toFinal);
to_final.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!"".equals(heightText.getText().toString())){
height = Double.parseDouble(heightText.getText().toString());
if (height > 0.0){
real_height = getValues(focal_length, height);
}
}
if (!"".equals(widthText.getText().toString())){
width = Double.parseDouble(widthText.getText().toString());
if (width > 0.0){
real_width = getValues(focal_length, height);
}
}
Double length;
if (real_height == real_width){
length = real_height;
} else if (real_height == _real_height || real_height == _real_width ) {
length = real_width;
} else if (real_width == _real_width || real_width == _real_height) {
length = real_height;
} else {
double[] all = {real_width,real_height,_real_height,_real_width};
length = findClosest(all);
}
mass = getMass(length,_real_width,_real_height, density);
//Toast.makeText(getApplicationContext(), mass.toString(), Toast.LENGTH_SHORT).show();
if (mass != 0.0){
Intent intent = ne