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 @@ ...@@ -18,18 +18,22 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> 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=".import_pictures" />
<activity android:name=".export_data" /> <activity android:name=".export_data">
<activity android:name=".foodInfo" />
<activity android:name=".login" />
<activity android:name=".MainActivity">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".foodInfo" />
<activity android:name=".login" />
<activity android:name=".MainActivity">
</activity>
</application> </application>
</manifest> </manifest>
\ No newline at end of file
...@@ -6,6 +6,7 @@ import android.database.sqlite.SQLiteDatabase; ...@@ -6,6 +6,7 @@ import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteOpenHelper;
public class database_helper extends SQLiteOpenHelper{ public class database_helper extends SQLiteOpenHelper{
public static final String DATABASE_NAME="calories.db"; public static final String DATABASE_NAME="calories.db";
public static final String TABLE_NAME="credentials"; public static final String TABLE_NAME="credentials";
public static final String COL_1="ID"; public static final String COL_1="ID";
......
...@@ -31,16 +31,22 @@ public class export_data extends AppCompatActivity { ...@@ -31,16 +31,22 @@ public class export_data extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_export_data); setContentView(R.layout.activity_export_data);
_txt_fruitName = (EditText)findViewById(R.id.txt_fruitName); _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() { _btn_next.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
fr_density = getCSVDATA(_txt_fruitName.getText().toString()); fr_density = getCSVDATA(_txt_fruitName.getText().toString());
if (fr_density != 0){ 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 intent = new Intent(export_data.this, import_pictures.class);
intent.putExtra("density", fr_density); intent.putExtra("density", fr_density);
intent.putExtra("Fruit", fruit);
startActivity(intent); startActivity(intent);
} else { } 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(); 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; ...@@ -2,6 +2,7 @@ package com.example.calorieestimator;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
...@@ -20,28 +21,29 @@ import org.json.JSONArray; ...@@ -20,28 +21,29 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.Arrays; import java.math.BigDecimal;
public class foodInfo extends AppCompatActivity { public class foodInfo extends AppCompatActivity {
TextView _api_result, _textv2_density; TextView _api_result, _title;
EditText _food_name; EditText _food_name;
Button _btn_calc; Button _btn_calc, _btn_start;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_food_info); 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); _api_result = (TextView)findViewById(R.id.api_view);
_textv2_density = (TextView)findViewById(R.id.textView_density); _title = (TextView)findViewById(R.id.textView_title);
_food_name = (EditText)findViewById(R.id.food_name); _btn_start = (Button)findViewById(R.id.btn_start);
_btn_calc = (Button)findViewById(R.id.btn_calc); _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() { _btn_calc.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
String food = _food_name.getText().toString(); String food = fruit;
String[] t = food.split(" ", 0); String[] t = food.split(" ", 0);
String api_helper = ""; String api_helper = "";
...@@ -64,14 +66,19 @@ public class foodInfo extends AppCompatActivity { ...@@ -64,14 +66,19 @@ public class foodInfo extends AppCompatActivity {
public void onResponse(JSONObject response) { public void onResponse(JSONObject response) {
try{ try{
JSONArray jsonArray = response.getJSONArray("foods"); JSONArray jsonArray = response.getJSONArray("foods");
JSONObject food = jsonArray.getJSONObject(0); JSONObject food = jsonArray.getJSONObject(0);
String description = food.getString("description"); String description = food.getString("description");
JSONArray foodNutrients = food.getJSONArray("foodNutrients"); JSONArray foodNutrients = food.getJSONArray("foodNutrients");
JSONObject nutrients = foodNutrients.getJSONObject(3); JSONObject nutrients = foodNutrients.getJSONObject(3);
String amount = nutrients.getString("nutrientNumber"); 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 kcal = nutrients.getString("unitName");
String final_str = description + ": " + amount + kcal; String final_str = amount + kcal;
_api_result.setText(final_str.toString()); _api_result.setText(final_str.toString());
//Log.e("Rest Response", response.toString()); //Log.e("Rest Response", response.toString());
...@@ -91,6 +98,13 @@ public class foodInfo extends AppCompatActivity { ...@@ -91,6 +98,13 @@ public class foodInfo extends AppCompatActivity {
} }
}); });
_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; ...@@ -11,13 +11,10 @@ import android.media.ExifInterface;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.provider.ContactsContract;
import android.util.Log; import android.util.Log;
import android.util.Rational;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.squareup.picasso.Picasso; import com.squareup.picasso.Picasso;
...@@ -27,7 +24,7 @@ import java.io.InputStream; ...@@ -27,7 +24,7 @@ import java.io.InputStream;
public class import_pictures extends AppCompatActivity { public class import_pictures extends AppCompatActivity {
Button _get_side, _btn_next; Button _get_side, to_side;
ImageView _side_view, _ruler; ImageView _side_view, _ruler;
private static final int IMAGE_PICK_CODE=1000; private static final int IMAGE_PICK_CODE=1000;
private static final int PERMISSION_CODE=1001; private static final int PERMISSION_CODE=1001;
...@@ -38,12 +35,12 @@ public class import_pictures extends AppCompatActivity { ...@@ -38,12 +35,12 @@ public class import_pictures extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_import_pictures); setContentView(R.layout.activity_import_pictures);
final Double density = getIntent().getExtras().getDouble("density"); final Double density = getIntent().getExtras().getDouble("density");
final String fruit = getIntent().getExtras().getString("Fruit");
_get_side = (Button)findViewById(R.id.btn_getSide); _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); _side_view = (ImageView)findViewById(R.id.imageView_side);
_ruler = (ImageView)findViewById(R.id.imageView_ruler); _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() { _get_side.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
...@@ -51,16 +48,18 @@ public class import_pictures extends AppCompatActivity { ...@@ -51,16 +48,18 @@ public class import_pictures extends AppCompatActivity {
openGallery(); openGallery();
} }
}); });
_btn_next.setOnClickListener(new View.OnClickListener() { to_side.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
//Toast.makeText(getApplicationContext(), focal_length, Toast.LENGTH_SHORT).show(); //Toast.makeText(getApplicationContext(), focal_length, Toast.LENGTH_SHORT).show();
if (pathStr == ""){ if (pathStr==""){
Toast.makeText(getApplicationContext(), "Please select a picture", Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), "Please select a picture", Toast.LENGTH_SHORT).show();
} else { } else {
//Toast.makeText(getApplicationContext(), focal_length + density.toString(), Toast.LENGTH_SHORT).show();
Intent intent = new Intent(import_pictures.this, side_ruler.class); Intent intent = new Intent(import_pictures.this, side_ruler.class);
intent.getIntExtra("Focal_length", Integer.valueOf(focal_length)); intent.putExtra("Focal_length", Integer.valueOf(focal_length));
intent.getDoubleExtra("density", density); intent.putExtra("density", density);
intent.putExtra("Fruit", fruit);
startActivity(intent); startActivity(intent);
} }
...@@ -110,11 +109,8 @@ public class import_pictures extends AppCompatActivity { ...@@ -110,11 +109,8 @@ public class import_pictures extends AppCompatActivity {
focal_length= exif.getAttribute(ExifInterface.TAG_FOCAL_LENGTH); focal_length= exif.getAttribute(ExifInterface.TAG_FOCAL_LENGTH);
focal_length = focal_length.split("/", 2)[0]; focal_length = focal_length.split("/", 2)[0];
} catch (IOException e){ } catch (IOException e){
Log.e("ERRORRRRR", e.toString());
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
......
...@@ -2,28 +2,68 @@ package com.example.calorieestimator; ...@@ -2,28 +2,68 @@ package com.example.calorieestimator;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView; import android.widget.Toast;
public class side_ruler extends AppCompatActivity { public class side_ruler extends AppCompatActivity {
EditText width, height; 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 @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_side_ruler); 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); width = (EditText)findViewById(R.id.width_text);
height = (EditText)findViewById(R.id.height_text); height = (EditText)findViewById(R.id.height_text);
Double real_width; to_topView = (Button)findViewById(R.id._btn_TopView);
Double real_height;
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);