From 6c307683a33562fb1d1773d562d695b18cc5ac28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yi=C4=9Fit=20=C3=87olako=C4=9Flu?= Date: Wed, 13 Mar 2019 14:36:22 +0300 Subject: [PATCH] Added Classes Finished navbar drawer --- MyCity/app/build.gradle | 1 + .../java/gq/yigit/mycity/MainActivity.java | 12 --- .../main/java/gq/yigit/mycity/WebRequest.java | 101 ++++++++++++++++++ .../gq/yigit/mycity/responseListener.java | 5 + MyCity/app/src/main/res/drawable/bus.xml | 9 ++ MyCity/app/src/main/res/drawable/check.xml | 9 ++ MyCity/app/src/main/res/drawable/house.xml | 18 ++++ .../app/src/main/res/drawable/navigation.xml | 9 ++ MyCity/app/src/main/res/drawable/parking.svg | 46 -------- MyCity/app/src/main/res/drawable/parking.xml | 12 +++ MyCity/app/src/main/res/drawable/star.xml | 9 ++ .../main/res/menu/activity_main_drawer.xml | 52 ++++----- MyCity/app/src/main/res/values/strings.xml | 3 + server_side/Chatbot/main.py | 2 +- 14 files changed, 204 insertions(+), 84 deletions(-) create mode 100644 MyCity/app/src/main/java/gq/yigit/mycity/WebRequest.java create mode 100644 MyCity/app/src/main/java/gq/yigit/mycity/responseListener.java create mode 100644 MyCity/app/src/main/res/drawable/bus.xml create mode 100644 MyCity/app/src/main/res/drawable/check.xml create mode 100644 MyCity/app/src/main/res/drawable/house.xml create mode 100644 MyCity/app/src/main/res/drawable/navigation.xml delete mode 100644 MyCity/app/src/main/res/drawable/parking.svg create mode 100644 MyCity/app/src/main/res/drawable/parking.xml create mode 100644 MyCity/app/src/main/res/drawable/star.xml diff --git a/MyCity/app/build.gradle b/MyCity/app/build.gradle index e5675b1..33e86be 100644 --- a/MyCity/app/build.gradle +++ b/MyCity/app/build.gradle @@ -20,6 +20,7 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') + api "cz.msebera.android:httpclient:4.4.1.2" implementation 'com.android.support:design:27.1.1' implementation 'com.android.support:appcompat-v7:27.0.0' implementation 'com.android.support:design:27.0.0' diff --git a/MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java b/MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java index 2379eb6..22e6374 100644 --- a/MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java +++ b/MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java @@ -80,19 +80,7 @@ public class MainActivity extends AppCompatActivity // Handle navigation view item clicks here. int id = item.getItemId(); - if (id == R.id.nav_camera) { - // Handle the camera action - } else if (id == R.id.nav_gallery) { - } else if (id == R.id.nav_slideshow) { - - } else if (id == R.id.nav_manage) { - - } else if (id == R.id.nav_share) { - - } else if (id == R.id.nav_send) { - - } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); diff --git a/MyCity/app/src/main/java/gq/yigit/mycity/WebRequest.java b/MyCity/app/src/main/java/gq/yigit/mycity/WebRequest.java new file mode 100644 index 0000000..96a1b28 --- /dev/null +++ b/MyCity/app/src/main/java/gq/yigit/mycity/WebRequest.java @@ -0,0 +1,101 @@ +package gq.yigit.mycity; + +import android.os.AsyncTask; +import android.util.Log; +import cz.msebera.android.httpclient.HttpResponse; +import cz.msebera.android.httpclient.NameValuePair; +import cz.msebera.android.httpclient.client.HttpClient; +import cz.msebera.android.httpclient.client.entity.UrlEncodedFormEntity; +import cz.msebera.android.httpclient.client.methods.HttpGet; +import cz.msebera.android.httpclient.client.methods.HttpPost; +import cz.msebera.android.httpclient.impl.client.HttpClientBuilder; +import cz.msebera.android.httpclient.message.BasicNameValuePair; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.*; + +public class WebRequest extends AsyncTask { + private String url; + private HashMap request_content; + private boolean request_type;//True = GET, False = POST + + private HttpClient client = HttpClientBuilder.create().build(); + private HttpGet get_request; + private HttpPost post_request; + private HttpResponse response; + private List listeners = new ArrayList<>(); + + + WebRequest(String url, boolean request_type, HashMap request_content){ + + this.url = url; + this.request_content = request_content; + this.request_type = request_type; + + if(request_type){ + + Iterator iterator = request_content.entrySet().iterator(); + this.url += "?"; + + while(iterator.hasNext()){ + Map.Entry pair = (Map.Entry)iterator.next(); + this.url += pair.getKey() + "=" + pair.getValue() + "&"; + iterator.remove(); + } + get_request = new HttpGet(this.url); + }else{ + post_request = new HttpPost(this.url); + } + } + + protected String doInBackground(Void... params){ + if(!request_type){ + try { + post_request = new HttpPost(url); + List pairs = new ArrayList<>(request_content.size()); + + Iterator iterator = request_content.entrySet().iterator(); + + while (iterator.hasNext()) { + Map.Entry pair = (Map.Entry) iterator.next(); + pairs.add(new BasicNameValuePair(pair.getKey().toString(), pair.getValue().toString())); + iterator.remove(); + } + post_request.setEntity(new UrlEncodedFormEntity(pairs)); + response = client.execute(post_request); + }catch (Exception e){ + Log.e("[ERROR](request:67): ", e.toString()); + } + }else{ + try { + response = client.execute(get_request); + }catch (Exception e){ + Log.e("[ERROR](request:74): ", e.toString()); + } + } + try { + BufferedReader rd = new BufferedReader + (new InputStreamReader( + response.getEntity().getContent())); + String line = ""; + String temp; + while ((temp = rd.readLine()) != null) { + line += temp; + } + return line; + }catch(Exception e){ + Log.e("[ERROR](request:87): ", e.toString()); + } + return "Error"; + } + protected void onPostExecute(String result){ + for (responseListener hl : listeners) + hl.receivedResponse(!result.equals("Error"),result); + } + + public void addListener(responseListener toAdd) { + listeners.add(toAdd); + } + +} \ No newline at end of file diff --git a/MyCity/app/src/main/java/gq/yigit/mycity/responseListener.java b/MyCity/app/src/main/java/gq/yigit/mycity/responseListener.java new file mode 100644 index 0000000..2810e2c --- /dev/null +++ b/MyCity/app/src/main/java/gq/yigit/mycity/responseListener.java @@ -0,0 +1,5 @@ +package gq.yigit.mycity; + +public interface responseListener { + void receivedResponse(boolean success, String response); +} \ No newline at end of file diff --git a/MyCity/app/src/main/res/drawable/bus.xml b/MyCity/app/src/main/res/drawable/bus.xml new file mode 100644 index 0000000..772f426 --- /dev/null +++ b/MyCity/app/src/main/res/drawable/bus.xml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/MyCity/app/src/main/res/drawable/check.xml b/MyCity/app/src/main/res/drawable/check.xml new file mode 100644 index 0000000..8e4c06c --- /dev/null +++ b/MyCity/app/src/main/res/drawable/check.xml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/MyCity/app/src/main/res/drawable/house.xml b/MyCity/app/src/main/res/drawable/house.xml new file mode 100644 index 0000000..a614b54 --- /dev/null +++ b/MyCity/app/src/main/res/drawable/house.xml @@ -0,0 +1,18 @@ + + + + + + + \ No newline at end of file diff --git a/MyCity/app/src/main/res/drawable/navigation.xml b/MyCity/app/src/main/res/drawable/navigation.xml new file mode 100644 index 0000000..fa83f87 --- /dev/null +++ b/MyCity/app/src/main/res/drawable/navigation.xml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/MyCity/app/src/main/res/drawable/parking.svg b/MyCity/app/src/main/res/drawable/parking.svg deleted file mode 100644 index 9440136..0000000 --- a/MyCity/app/src/main/res/drawable/parking.svg +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/MyCity/app/src/main/res/drawable/parking.xml b/MyCity/app/src/main/res/drawable/parking.xml new file mode 100644 index 0000000..bfd3a40 --- /dev/null +++ b/MyCity/app/src/main/res/drawable/parking.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/MyCity/app/src/main/res/drawable/star.xml b/MyCity/app/src/main/res/drawable/star.xml new file mode 100644 index 0000000..872c48f --- /dev/null +++ b/MyCity/app/src/main/res/drawable/star.xml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/MyCity/app/src/main/res/menu/activity_main_drawer.xml b/MyCity/app/src/main/res/menu/activity_main_drawer.xml index 3c52e85..a78f6ac 100644 --- a/MyCity/app/src/main/res/menu/activity_main_drawer.xml +++ b/MyCity/app/src/main/res/menu/activity_main_drawer.xml @@ -3,35 +3,37 @@ xmlns:tools="http://schemas.android.com/tools" tools:showIn="navigation_view"> - - - - - - + + + + + + + - + + android:id="@+id/rating" + android:icon="@drawable/star" + android:title="Rate"/> + + android:id="@+id/utilities" + android:icon="@drawable/house" + android:title="Utilities"/> diff --git a/MyCity/app/src/main/res/values/strings.xml b/MyCity/app/src/main/res/values/strings.xml index aa87117..4d4cd64 100644 --- a/MyCity/app/src/main/res/values/strings.xml +++ b/MyCity/app/src/main/res/values/strings.xml @@ -6,4 +6,7 @@ android.studio@android.com Navigation header Settings + Transport + For you + diff --git a/server_side/Chatbot/main.py b/server_side/Chatbot/main.py index 93f5409..89e1d70 100644 --- a/server_side/Chatbot/main.py +++ b/server_side/Chatbot/main.py @@ -18,9 +18,9 @@ def getData( searched, data, data_final ): data_final[ key ] = data[ key ] else: getData( searched[ key ], data[ key ], data_final ) +parser = Parser() while True: sentence = raw_input("You:") - parser = Parser() #Parse the input tokenized = nltk.word_tokenize( sentence )