From d88b59ec5c1473261ed9c0e2b9612ab1915bd922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yi=C4=9Fit=20=C3=87olako=C4=9Flu?= Date: Sun, 24 Jun 2018 19:03:45 +0300 Subject: [PATCH] near finish nearly finished product proggress. finished product info, hanndling errors --- Barcode_Reader_Python/.idea/workspace.xml | 71 +++++++++++-------- Barcode_Reader_Python/database_append.py | 26 ++++--- .../java/gq/yigit/foodcloud/LearnMore.java | 56 ++++++++++++--- .../java/gq/yigit/foodcloud/MainActivity.java | 13 ++-- .../main/java/gq/yigit/foodcloud/PHPComm.java | 4 +- .../java/gq/yigit/foodcloud/ProductInfo.java | 17 ++++- .../main/res/layout/activity_learn_more.xml | 6 +- .../main/res/layout/activity_product_info.xml | 4 +- database/content/Processes/1.json | 2 +- database/content/Processes/2.json | 2 +- 10 files changed, 139 insertions(+), 62 deletions(-) diff --git a/Barcode_Reader_Python/.idea/workspace.xml b/Barcode_Reader_Python/.idea/workspace.xml index 418fa5e..f37bc3f 100644 --- a/Barcode_Reader_Python/.idea/workspace.xml +++ b/Barcode_Reader_Python/.idea/workspace.xml @@ -2,13 +2,12 @@ - - - + + - + @@ -48,17 +47,26 @@ - + - + - + + + + + + + + + + @@ -102,8 +110,8 @@ @@ -162,7 +170,7 @@ - + @@ -411,6 +419,13 @@ + + + + + + + @@ -534,16 +549,9 @@ - - - - - - - - + @@ -553,7 +561,7 @@ - + @@ -561,7 +569,14 @@ - + + + + + + + + diff --git a/Barcode_Reader_Python/database_append.py b/Barcode_Reader_Python/database_append.py index 8c3c9c1..8ecc395 100644 --- a/Barcode_Reader_Python/database_append.py +++ b/Barcode_Reader_Python/database_append.py @@ -6,11 +6,11 @@ data_format_prod = { } data_format_proc = { - 'Harvested': {'Date': '', 'Location': '', 'Product': ''}, - 'Transport1': {'Duration': 0, 'Moved to,from': '-', 'Condition': True, 'Stopped': False}, - 'Process': {'Location': '', 'Processes': ''}, - 'Transport2': {'Duration': 0, 'Moved to,from': '-', 'Condition': 0, 'Stopped': False}, - 'Packaging': {'Location': '', 'Material': '', 'Cancerogen': True} + 'Harvested': {'Date': '', 'Location': '', 'Product': '','Problematic':False}, + 'Transport1': {'Duration': 0, 'Moved to,from': '-', 'Condition': True, 'Stopped': False,'Problematic':False}, + 'Process': {'Location': '', 'Processes': '','Problematic':False}, + 'Transport2': {'Duration': 0, 'Moved to,from': '-', 'Condition': 0, 'Stopped': False,'Problematic':False}, + 'Packaging': {'Location': '', 'Material': '', 'Cancerogen': True,'Problematic':False} } data_1_prod = { @@ -28,33 +28,37 @@ data_1_proc = { 'Harvested': { 'Date': '18.08.2018', 'Location': 'Larson Family', 'Product': 'Raw Milk' +,'Problematic':False }, 'Transport1': { 'Duration': 9, 'Moved to,from': 'Larson Family-McCarty Family Farms', 'Condition': True, 'Stopped': True +,'Problematic':True }, 'Process': { 'Location': 'McCarty Family Farms', 'Processes': 'Reverse Osmosis,Nanofiltration,Ultrafiltration,Microfiltration' +,'Problematic':False }, 'Transport2': { 'Duration': 13, 'Moved to,from': 'McCarty Family Farms-JJX Packaging', 'Condition': True, 'Stopped': True +,'Problematic':False }, - 'Packaging': {'Location': 'JJX Packaging', 'Material': 'Carton', 'Cancerogen': False} + 'Packaging': {'Location': 'JJX Packaging', 'Material': 'Carton', 'Cancerogen': False,'Problematic':True} } data_2_proc = { 'Harvested': { 'Date': '27.01.2018', 'Location': 'India', - 'Product': 'Cocoa' + 'Product': 'Cocoa','Problematic':True }, - 'Transport1': {'Duration': 71, 'Moved to,from': 'India-Nestle ', 'Condition': True, 'Stopped': True}, - 'Process': {'Location': 'Nestle', 'Processes': 'Roasting,Pulp,Conching,Moulding'}, + 'Transport1': {'Duration': 71, 'Moved to,from': 'India-Nestle ', 'Condition': True, 'Stopped': True,'Problematic':False}, + 'Process': {'Location': 'Nestle', 'Processes': 'Roasting,Pulp,Conching,Moulding','Problematic':False}, 'Transport2': { 'Duration': 4, 'Moved to,from': 'Nestle-Ulma Packaging', 'Condition': True, - 'Stopped': False + 'Stopped': False,'Problematic':False }, - 'Packaging': {'Location': 'Ulma Packaging', 'Material': 'Foil', 'Cancerogen': False} + 'Packaging': {'Location': 'Ulma Packaging', 'Material': 'Foil', 'Cancerogen': False,'Problematic':False} } Products = [data_1_prod, data_2_prod] diff --git a/FoodCloud/app/src/main/java/gq/yigit/foodcloud/LearnMore.java b/FoodCloud/app/src/main/java/gq/yigit/foodcloud/LearnMore.java index 31d079d..dcc4e4f 100644 --- a/FoodCloud/app/src/main/java/gq/yigit/foodcloud/LearnMore.java +++ b/FoodCloud/app/src/main/java/gq/yigit/foodcloud/LearnMore.java @@ -9,6 +9,10 @@ import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; + +import org.json.JSONException; +import org.json.JSONObject; + import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -21,18 +25,19 @@ public class LearnMore extends AppCompatActivity implements View.OnClickListener public ImageView packaging; public ImageView trans1; public ImageView trans2; - public ImageView factory_cond; - public ImageView farm_cond; - public ImageView packaging_cond; - public ImageView trans1_cond; - public ImageView trans2_cond; + static public ImageView factory_cond; + static public ImageView farm_cond; + static public ImageView packaging_cond; + static public ImageView trans1_cond; + static public ImageView trans2_cond; + public Button back_to_main; public Map someMap; public String prod_loc; - + static public JSONObject process; @Override protected void onCreate(Bundle savedInstanceState) { - + System.gc(); Bundle extras = getIntent().getExtras(); if (extras != null) { prod_loc_more = extras.getString("key"); @@ -40,24 +45,59 @@ public class LearnMore extends AppCompatActivity implements View.OnClickListener super.onCreate(savedInstanceState); setContentView(R.layout.activity_learn_more); factory = (ImageView) findViewById(R.id.factory); + factory_cond = (ImageView) findViewById(R.id.factory_cond); factory.setOnClickListener(this); farm = (ImageView) findViewById(R.id.farm); + farm_cond = (ImageView) findViewById(R.id.farm_cond); farm.setOnClickListener(this); packaging = (ImageView) findViewById(R.id.packaging); + packaging_cond = (ImageView) findViewById(R.id.packaging_cond); packaging.setOnClickListener(this); trans1 = (ImageView) findViewById(R.id.trans1); + trans1_cond = (ImageView) findViewById(R.id.trans1_cond); trans1.setOnClickListener(this); trans2 = (ImageView) findViewById(R.id.trans2); + trans2_cond = (ImageView) findViewById(R.id.trans2_cond); trans2.setOnClickListener(this); back_to_main = (Button) findViewById(R.id.go_back_to_main); back_to_main.setOnClickListener(this); + PHPComm comm = new PHPComm(this); + PHPComm.decide = "Proc"; + comm.execute("get", prod_loc_more, "Processes"); } public void onClick(View v){ - if(v.getId() == R.id.back_to_main){ + if(v.getId() == R.id.go_back_to_main){ Intent i = new Intent(LearnMore.this, MainActivity.class); startActivity(i); } } + static public void adjustImg(ImageView comp,String stage) { + try { + if ((boolean) process.getJSONObject(stage).get("Problematic")) { + comp.setImageResource(R.mipmap.warning); + comp.bringToFront(); + } else { + comp.setImageResource(R.mipmap.check); + comp.bringToFront(); + } + } catch (JSONException e) { + Log.d(TAG, "An error ocuured with the json"); + } + } + + static public void continueProg(String result){ + try { + process = new JSONObject(result); + }catch (JSONException e){ + Log.d(TAG,"An error ocuured with the json"); + } + Log.d(TAG,"Received JSON: " + process.toString()); + adjustImg(factory_cond,"Process"); + adjustImg(farm_cond,"Harvested"); + adjustImg(packaging_cond,"Packaging"); + adjustImg(trans1_cond,"Transport1"); + adjustImg(trans2_cond,"Transport2"); + } } diff --git a/FoodCloud/app/src/main/java/gq/yigit/foodcloud/MainActivity.java b/FoodCloud/app/src/main/java/gq/yigit/foodcloud/MainActivity.java index ddf1848..d89465c 100644 --- a/FoodCloud/app/src/main/java/gq/yigit/foodcloud/MainActivity.java +++ b/FoodCloud/app/src/main/java/gq/yigit/foodcloud/MainActivity.java @@ -25,7 +25,7 @@ public class MainActivity extends AppCompatActivity implements OnClickListener{ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - + System.gc(); scanBtn = (Button)findViewById(R.id.scan_button); scanBtn.setOnClickListener(this); @@ -51,13 +51,18 @@ public class MainActivity extends AppCompatActivity implements OnClickListener{ public void onActivityResult(int requestCode, int resultCode, Intent intent) { IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent); - if (scanningResult != null) { - String scanContent = scanningResult.getContents(); + String scanContent = scanningResult.getContents(); + try{ + scanContent.toString(); Intent i = new Intent(MainActivity.this, ProductInfo.class); i.putExtra("key",scanContent); startActivity(i); } - else{ + catch(NullPointerException e) { + Toast toast = Toast.makeText(getApplicationContext(), + "No scan data received!", Toast.LENGTH_SHORT); + toast.show(); + }catch(RuntimeException e){ Toast toast = Toast.makeText(getApplicationContext(), "No scan data received!", Toast.LENGTH_SHORT); toast.show(); diff --git a/FoodCloud/app/src/main/java/gq/yigit/foodcloud/PHPComm.java b/FoodCloud/app/src/main/java/gq/yigit/foodcloud/PHPComm.java index 1a19bdc..ea79c71 100644 --- a/FoodCloud/app/src/main/java/gq/yigit/foodcloud/PHPComm.java +++ b/FoodCloud/app/src/main/java/gq/yigit/foodcloud/PHPComm.java @@ -30,7 +30,7 @@ public class PHPComm extends AsyncTask { @Override protected String doInBackground(String... params) { String type = params[0]; - String login_url = "http://192.168.43.125/database/communication/comm.php"; + String login_url = "http://192.168.1.21/database/communication/comm.php"; if(type.equals("get")) { try { Log.d(TAG,"received get"); @@ -84,6 +84,8 @@ public class PHPComm extends AsyncTask { Log.d(TAG,decide); if(decide == "Prod") { ProductInfo.continueApp(result); + }else{ + LearnMore.continueProg(result); } } diff --git a/FoodCloud/app/src/main/java/gq/yigit/foodcloud/ProductInfo.java b/FoodCloud/app/src/main/java/gq/yigit/foodcloud/ProductInfo.java index f0668a0..35b98a6 100644 --- a/FoodCloud/app/src/main/java/gq/yigit/foodcloud/ProductInfo.java +++ b/FoodCloud/app/src/main/java/gq/yigit/foodcloud/ProductInfo.java @@ -70,7 +70,8 @@ public class ProductInfo extends AppCompatActivity implements OnClickListener { BBD = (TextView) findViewById(R.id.BBD); Processed = (TextView) findViewById(R.id.Process); Nutrients = (TextView) findViewById(R.id.nutrients); - Bundle extras = getIntent().getExtras(); + Bundle extras = + getIntent().getExtras(); if (extras != null) { prod_loc = extras.getString("key"); } @@ -88,6 +89,17 @@ public class ProductInfo extends AppCompatActivity implements OnClickListener { Intent i = new Intent(ProductInfo.this, MainActivity.class); startActivity(i); }if (v.getId() == R.id.journey) { + allergens_array = null; + nutrients_array = null; + //expiry_date = null; + nutrients = null; + allergens = null; + processed = null; + name = null; + cooked = null; + cal = null; + bbd = null; + System.gc(); Intent i = new Intent(ProductInfo.this, LearnMore.class); i.putExtra("key", prod_loc); startActivity(i); @@ -115,7 +127,6 @@ public class ProductInfo extends AppCompatActivity implements OnClickListener { }catch (NullPointerException e){ Log.d(TAG,"Received null data!"); } - Log.d(TAG,allergens); if(processed.length() < 4){ Processed.setText("None"); } @@ -143,7 +154,7 @@ public class ProductInfo extends AppCompatActivity implements OnClickListener { for(int i = 0; i < nutrients_array.length();i++) { try { nutrients_print = nutrients_print + nutrients_array.get(i); - }catch (JSONException e){ + }catch (JSONException e){ Log.d(TAG,"An error occured with json"); } if(i != nutrients_array.length()-1){ diff --git a/FoodCloud/app/src/main/res/layout/activity_learn_more.xml b/FoodCloud/app/src/main/res/layout/activity_learn_more.xml index 1c625ae..de1a5c9 100644 --- a/FoodCloud/app/src/main/res/layout/activity_learn_more.xml +++ b/FoodCloud/app/src/main/res/layout/activity_learn_more.xml @@ -213,8 +213,8 @@