diff --git a/Barcode_Reader_Python/.idea/workspace.xml b/Barcode_Reader_Python/.idea/workspace.xml index ab95389..418fa5e 100644 --- a/Barcode_Reader_Python/.idea/workspace.xml +++ b/Barcode_Reader_Python/.idea/workspace.xml @@ -2,19 +2,13 @@ - - - - - - - - + + + + - - - + - - - + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -84,9 +101,9 @@ @@ -126,12 +143,12 @@ - + - + - + @@ -394,6 +411,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -459,7 +511,6 @@ - @@ -475,14 +526,42 @@ - - - + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Barcode_Reader_Python/database_read.py b/Barcode_Reader_Python/database_read.py index a0ccf06..977e2a6 100755 --- a/Barcode_Reader_Python/database_read.py +++ b/Barcode_Reader_Python/database_read.py @@ -1,22 +1,11 @@ -import pyrebase +import urllib2, urllib -config = { - "apiKey": "AIzaSyD3bXRjLxEAVOKtj8hpjO4iI3Nn32F7agU", - "authDomain": "foodcloud-f6eb1.firebaseapp.com", - "databaseURL": "https://foodcloud-f6eb1.firebaseio.com/", - "storageBucket": "foodcloud-f6eb1.appspot.com" -} +def getData(id): + dbdata = [('id', id), ('value', 'Products'),('content','BBD')] # The first is the var name the second is the value + dbdata = urllib.urlencode(dbdata) + path = 'http://192.168.1.21/database/communication/comm.php' # the url you want to POST to + req = urllib2.Request(path, dbdata) + req.add_header("Content-type", "application/x-www-form-urlencoded") + page = urllib2.urlopen(req).read() -firebase = pyrebase.initialize_app(config) - -auth = firebase.auth() - -user = auth.sign_in_with_email_and_password('yigitcolakohlu@gmail.com', 'FoodWro2018') - -db = firebase.database() - -database_content = db.child("Products").get().val() - -def getDate(product): - return str((database_content[int(product)]['BBD'])) diff --git a/FoodCloud/app/src/main/java/gq/yigit/foodcloud/GetInfo.java b/FoodCloud/app/src/main/java/gq/yigit/foodcloud/GetInfo.java index 89a28c3..b387643 100644 --- a/FoodCloud/app/src/main/java/gq/yigit/foodcloud/GetInfo.java +++ b/FoodCloud/app/src/main/java/gq/yigit/foodcloud/GetInfo.java @@ -1,16 +1,27 @@ package gq.yigit.foodcloud; +import android.content.DialogInterface; +import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.view.View; import android.webkit.WebView; +import android.widget.Button; -public class GetInfo extends AppCompatActivity { - +public class GetInfo extends AppCompatActivity implements View.OnClickListener { + public Button back_to_main; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_get_info); WebView myWebView = (WebView) findViewById(R.id.info); myWebView.loadUrl("https://www.welthungerhilfe.org/our-work/approaches/food-security-standard/"); + back_to_main = (Button) findViewById(R.id.back_to_main); + back_to_main.setOnClickListener(this); + } + public void onClick(View v){ + + Intent i = new Intent(GetInfo.this, MainActivity.class); + startActivity(i); } } 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 541c449..31d079d 100644 --- a/FoodCloud/app/src/main/java/gq/yigit/foodcloud/LearnMore.java +++ b/FoodCloud/app/src/main/java/gq/yigit/foodcloud/LearnMore.java @@ -9,13 +9,6 @@ import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; - -import com.google.firebase.database.DataSnapshot; -import com.google.firebase.database.DatabaseError; -import com.google.firebase.database.DatabaseReference; -import com.google.firebase.database.FirebaseDatabase; -import com.google.firebase.database.ValueEventListener; - import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -36,9 +29,6 @@ public class LearnMore extends AppCompatActivity implements View.OnClickListener public Button back_to_main; public Map someMap; public String prod_loc; - Map map = new HashMap(); - FirebaseDatabase database = FirebaseDatabase.getInstance(); - DatabaseReference myRef = database.getReference(); @Override protected void onCreate(Bundle savedInstanceState) { @@ -46,7 +36,6 @@ public class LearnMore extends AppCompatActivity implements View.OnClickListener Bundle extras = getIntent().getExtras(); if (extras != null) { prod_loc_more = extras.getString("key"); - //The key argument here must match that used in the other activity } super.onCreate(savedInstanceState); setContentView(R.layout.activity_learn_more); @@ -66,35 +55,9 @@ public class LearnMore extends AppCompatActivity implements View.OnClickListener } public void onClick(View v){ - if(v.getId() == R.id.go_back_to_main){ + if(v.getId() == R.id.back_to_main){ Intent i = new Intent(LearnMore.this, MainActivity.class); startActivity(i); } - myRef.addValueEventListener(new ValueEventListener() { - @Override - public void onDataChange(DataSnapshot dataSnapshot) { - Bundle extras = getIntent().getExtras(); - if (extras != null) { - prod_loc = extras.getString("key"); - //The key argument here must match that used in the other activity - } - // This method is called once with the initial value and again - // whenever data at this location is updated. - someMap = (Map) dataSnapshot.getValue(); - ArrayList al1 = new ArrayList(); - al1 = (ArrayList) someMap.get("Production"); - al1.remove(0); - - - } - - @Override - public void onCancelled(DatabaseError error) { - // Failed to read value - Log.w(TAG, "Failed to read value.", error.toException()); - } - - }); - } - + } } 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 89133e7..1a19bdc 100644 --- a/FoodCloud/app/src/main/java/gq/yigit/foodcloud/PHPComm.java +++ b/FoodCloud/app/src/main/java/gq/yigit/foodcloud/PHPComm.java @@ -20,6 +20,7 @@ import java.net.URLEncoder; public class PHPComm extends AsyncTask { private static final String TAG = "MainActivity"; + public static String decide; Context context; AlertDialog alertDialog; PHPComm (Context ctx) { @@ -29,7 +30,7 @@ public class PHPComm extends AsyncTask { @Override protected String doInBackground(String... params) { String type = params[0]; - String login_url = "http://192.168.1.21/database/communication/comm.php"; + String login_url = "http://192.168.43.125/database/communication/comm.php"; if(type.equals("get")) { try { Log.d(TAG,"received get"); @@ -61,8 +62,10 @@ public class PHPComm extends AsyncTask { return result; } catch (MalformedURLException e) { e.printStackTrace(); + Log.d(TAG,"MalformedURL"); } catch (IOException e) { e.printStackTrace(); + Log.d(TAG,"IOExcept"); } } return null; @@ -78,7 +81,11 @@ public class PHPComm extends AsyncTask { protected void onPostExecute(String result) { alertDialog.setMessage(result); Log.d(TAG, "AlertBoxSet " + result); - ProductInfo.continueApp(result); + Log.d(TAG,decide); + if(decide == "Prod") { + ProductInfo.continueApp(result); + } + } @Override 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 9ee337a..f0668a0 100644 --- a/FoodCloud/app/src/main/java/gq/yigit/foodcloud/ProductInfo.java +++ b/FoodCloud/app/src/main/java/gq/yigit/foodcloud/ProductInfo.java @@ -14,22 +14,13 @@ END PRAYER package gq.yigit.foodcloud; import android.content.Intent; -import android.nfc.Tag; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.TextView; import android.widget.Button; - -import com.google.api.client.json.JsonObjectParser; -import com.google.firebase.database.*; -import java.util.HashMap; -import java.util.Map; -import java.util.ArrayList; import android.view.View.OnClickListener; -import android.widget.Toast; - import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -78,12 +69,14 @@ public class ProductInfo extends AppCompatActivity implements OnClickListener { Cooked = (TextView) findViewById(R.id.cooked); BBD = (TextView) findViewById(R.id.BBD); Processed = (TextView) findViewById(R.id.Process); + Nutrients = (TextView) findViewById(R.id.nutrients); Bundle extras = getIntent().getExtras(); if (extras != null) { prod_loc = extras.getString("key"); } PHPComm comm = new PHPComm(this); + PHPComm.decide = "Prod"; comm.execute("get", prod_loc, "Products"); @@ -123,6 +116,9 @@ public class ProductInfo extends AppCompatActivity implements OnClickListener { Log.d(TAG,"Received null data!"); } Log.d(TAG,allergens); + if(processed.length() < 4){ + Processed.setText("None"); + } if(allergens.length() < 7) { Allergens.setText("None"); }else{ @@ -138,28 +134,32 @@ public class ProductInfo extends AppCompatActivity implements OnClickListener { } Allergens.setText(allergens_print); } - /* - Nutrients = (TextView) findViewById(R.id.nutrients); + + nutrients_print = ""; - if(nutrients.isEmpty()) { - Nutrients.setText("Nutrients : None"); + if(nutrients.length() < 7) { + Nutrients.setText("None"); }else{ - for(int i = 0; i < nutrients.size();i++) { - nutrients_print = nutrients_print + nutrients.get(i); - if(i != nutrients.size() -1){ + for(int i = 0; i < nutrients_array.length();i++) { + try { + nutrients_print = nutrients_print + nutrients_array.get(i); + }catch (JSONException e){ + Log.d(TAG,"An error occured with json"); + } + if(i != nutrients_array.length()-1){ nutrients_print = nutrients_print + " , "; } } - Nutrients.setText("Nutrients : " + nutrients_print); + Nutrients.setText(nutrients_print); } -*/ + try { Cal.setText(cal); allergens_print = ""; - Cooked.setText("Cooked : " + cooked); + Cooked.setText(cooked); BBD.setText(bbd); - Processed.setText("Process : " + processed); + Processed.setText(processed); Name.setText(name); }catch(NullPointerException e){ 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 664db16..1c625ae 100644 --- a/FoodCloud/app/src/main/res/layout/activity_learn_more.xml +++ b/FoodCloud/app/src/main/res/layout/activity_learn_more.xml @@ -215,8 +215,10 @@ android:layout_width="160dp" android:layout_height="36dp" - android:layout_marginEnd="16dp" + android:layout_marginEnd="8dp" + android:layout_marginStart="8dp" + android:layout_marginTop="120dp" android:background="@drawable/buttonshape" android:shadowColor="#A8A8A8" android:shadowDx="0" @@ -225,7 +227,11 @@ android:text="@string/back" android:textColor="#000000" android:textSize="12sp" - app:layout_constraintEnd_toEndOf="parent" - tools:layout_editor_absoluteY="415dp" /> + app:layout_constraintBottom_toBottomOf="@+id/imageView16" + app:layout_constraintEnd_toEndOf="@+id/trans2" + app:layout_constraintHorizontal_bias="1.0" + app:layout_constraintStart_toStartOf="@+id/packaging_cond" + app:layout_constraintTop_toBottomOf="@+id/trans2" + app:layout_constraintVertical_bias="0.0" /> \ No newline at end of file diff --git a/database/communication/.idea/php.xml b/database/communication/.idea/php.xml new file mode 100644 index 0000000..d81b2e5 --- /dev/null +++ b/database/communication/.idea/php.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/database/communication/.idea/workspace.xml b/database/communication/.idea/workspace.xml index dcb7846..f57475b 100644 --- a/database/communication/.idea/workspace.xml +++ b/database/communication/.idea/workspace.xml @@ -10,7 +10,7 @@ - + @@ -23,8 +23,8 @@ - - + + @@ -65,9 +65,14 @@ - -