diff --git a/.idea/libraries/gson_2_8_0.xml b/.idea/libraries/gson_2_8_0.xml new file mode 100644 index 0000000..cbabd72 --- /dev/null +++ b/.idea/libraries/gson_2_8_0.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/volley_1_0_0.xml b/.idea/libraries/volley_1_0_0.xml new file mode 100644 index 0000000..8e317b7 --- /dev/null +++ b/.idea/libraries/volley_1_0_0.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 62f7122..4a14b8f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -26,7 +26,7 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) + compile fileTree(include: ['*.jar'], dir: 'libs') androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) @@ -35,5 +35,6 @@ dependencies { compile 'com.google.android.gms:play-services:10.0.1' compile 'com.android.support:multidex:1.0.1' testCompile 'junit:junit:4.12' - + compile 'com.google.code.gson:gson:2.8.0' + compile 'com.android.volley:volley:1.0.0' } diff --git a/app/src/debug/res/values/google_maps_api.xml b/app/src/debug/res/values/google_maps_api.xml index 957beee..2a66084 100644 --- a/app/src/debug/res/values/google_maps_api.xml +++ b/app/src/debug/res/values/google_maps_api.xml @@ -16,6 +16,6 @@ string in this file. --> - AIzaSyBRmipbUtS7TF5c9biaFgR7D__JwtELKmk + AIzaSyCBAPcAmX5NUu2LB4fXw8eTd0Zp025nUYY diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 26698e0..99c178a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -8,6 +8,7 @@ location permissions for the 'MyLocation' functionality. --> + USE GSON to Parse JSON + + private LatLng test; + + public MarkerData(){ + test = new LatLng(28.7037992,77.1006268); + } + + public LatLng getTest() { + return test; + } + + public void setTest(LatLng test) { + this.test = test; + } +} diff --git a/app/src/main/java/com/pulkit4tech/privy/data/PrivyPost.java b/app/src/main/java/com/pulkit4tech/privy/data/PrivyPost.java new file mode 100644 index 0000000..ce5630a --- /dev/null +++ b/app/src/main/java/com/pulkit4tech/privy/data/PrivyPost.java @@ -0,0 +1,5 @@ +package com.pulkit4tech.privy.data; + +public class PrivyPost { + +} diff --git a/app/src/main/java/com/pulkit4tech/privy/utilities/RequestData.java b/app/src/main/java/com/pulkit4tech/privy/utilities/RequestData.java new file mode 100644 index 0000000..bc74797 --- /dev/null +++ b/app/src/main/java/com/pulkit4tech/privy/utilities/RequestData.java @@ -0,0 +1,91 @@ +package com.pulkit4tech.privy.utilities; + +import android.content.Context; +import android.net.Uri; +import android.util.Log; +import android.widget.Toast; + +import com.android.volley.Request; +import com.android.volley.RequestQueue; +import com.android.volley.Response; +import com.android.volley.VolleyError; +import com.android.volley.toolbox.StringRequest; +import com.android.volley.toolbox.Volley; +import com.google.android.gms.maps.GoogleMap; +import com.google.android.gms.maps.model.LatLng; +import com.google.android.gms.maps.model.MarkerOptions; +import com.pulkit4tech.privy.R; +import com.pulkit4tech.privy.data.MarkerData; + +import java.util.ArrayList; + +import static com.pulkit4tech.privy.constants.Constants.DEBUG; + + +public class RequestData { + + private LatLng myLocation; + private ArrayList markerData; + private RequestQueue requestQueue; + private Context mContext; + private GoogleMap mMap; + + private String LOCATION = "location"; + private String NAME_KEY = "name"; + private String NAME_VALUE = "toilet"; + private String GOOGLE_MAP_API_KEY = "key"; + private String MAPS = "maps"; + private String API = "api"; + private String PLACE = "place"; + private String NEARBY = "nearbysearch"; + private String TYPE = "json"; + + public RequestData(Context mContext, GoogleMap mMap, LatLng myLocation){ + this.myLocation = myLocation; + this.mContext = mContext; + this.mMap = mMap; + } + + public void getMarkerData(){ + requestQueue = Volley.newRequestQueue(mContext); + Uri.Builder builder = new Uri.Builder(); + builder.scheme("https") + .authority(mContext.getResources().getString(R.string.request_api)) + .appendPath(MAPS) + .appendPath(API) + .appendPath(PLACE) + .appendPath(NEARBY) + .appendPath(TYPE) + .encodedQuery(LOCATION + "=" +String.format("%f,%f",myLocation.latitude,myLocation.longitude)) + .appendQueryParameter(NAME_KEY,NAME_VALUE) + .appendQueryParameter(GOOGLE_MAP_API_KEY,mContext.getResources().getString(R.string.google_maps_key)); + + final String requestUrl = builder.build().toString(); + Log.d(DEBUG,"URL: " + requestUrl); + + StringRequest request = new StringRequest(Request.Method.GET, requestUrl, new Response.Listener() { + @Override + public void onResponse(String response) { + // testing response + Toast.makeText(mContext,"Got response",Toast.LENGTH_SHORT).show(); + Log.d(DEBUG, "Response: " + response); + + // dummy data test TODO : Replace with JSON parsing + markerData = new ArrayList<>(); + markerData.add(new MarkerData()); + + for (MarkerData data : markerData){ + mMap.addMarker(new MarkerOptions().position(data.getTest()).title("Test")); + } + } + }, new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + Toast.makeText(mContext,"ERROR!!",Toast.LENGTH_SHORT).show(); + Log.d(DEBUG, error.toString()); + } + }); + + requestQueue.add(request); + } +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 19f6115..bbb6a82 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,4 +1,5 @@ Privy Nearby Privy\'s + maps.googleapis.com