diff --git a/.idea/.name b/.idea/.name
new file mode 100644
index 0000000..77d4dd9
--- /dev/null
+++ b/.idea/.name
@@ -0,0 +1 @@
+WebApplicationWithSpring
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..61a9130
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index d291b3d..9bba60d 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -1,15 +1,20 @@
+
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..a5f05cd
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 37a7509..d5d35ec 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,6 +1,6 @@
-
+
diff --git a/app/build.gradle b/app/build.gradle
index bd6130d..8723b32 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -38,6 +38,7 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
+ implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
@@ -46,4 +47,8 @@ dependencies {
// implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.gms:play-services:12.0.1'
implementation 'com.google.android.material:material:1.0.0'
+ implementation 'org.jetbrains:annotations-java5:15.0'
+ implementation 'com.android.volley:volley:1.1.0'
+ implementation 'com.google.code.gson:gson:2.8.6'
+
}
diff --git a/app/src/androidTest/java/com/example/webapplicationwithspring/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/webapplicationwithspring/ExampleInstrumentedTest.java
index b947ddb..c3ba629 100644
--- a/app/src/androidTest/java/com/example/webapplicationwithspring/ExampleInstrumentedTest.java
+++ b/app/src/androidTest/java/com/example/webapplicationwithspring/ExampleInstrumentedTest.java
@@ -2,13 +2,13 @@
import android.content.Context;
-import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.platform.app.InstrumentationRegistry;
import org.junit.Test;
import org.junit.runner.RunWith;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
/**
* Instrumented test, which will execute on an Android device.
diff --git "a/app/src/main - \320\257\321\200\320\273\321\213\320\272.lnk" "b/app/src/main - \320\257\321\200\320\273\321\213\320\272.lnk"
new file mode 100644
index 0000000..cb3d0e4
Binary files /dev/null and "b/app/src/main - \320\257\321\200\320\273\321\213\320\272.lnk" differ
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index d0dfa91..9f9f063 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -11,9 +11,12 @@
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
+ android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
- android:theme="@style/AppTheme">
+ android:theme="@style/AppTheme"
+ android:usesCleartextTraffic="true">
+
+ android:value="AIzaSyD4SHywIY-5Z4t_zs1O89Iy9eyvNt2QfdY" />
@@ -34,6 +37,7 @@
+
\ No newline at end of file
diff --git a/app/src/main/java/com/example/webapplicationwithspring/EventFragment.java b/app/src/main/java/com/example/webapplicationwithspring/EventFragment.java
new file mode 100644
index 0000000..e8f5560
--- /dev/null
+++ b/app/src/main/java/com/example/webapplicationwithspring/EventFragment.java
@@ -0,0 +1,46 @@
+package com.example.webapplicationwithspring;
+
+import android.app.Fragment;
+import android.content.Context;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.example.webapplicationwithspring.Events.EventsController;
+
+// class for the event fragment click
+public class EventFragment extends Fragment {
+// static class creation with parameter index, index is needed to display particular event from eventController
+ public static EventFragment newInstance(int index) {
+ EventFragment f = new EventFragment();
+ Bundle args = new Bundle();
+ args.putInt("index", index);
+ f.setArguments(args);
+ return f;
+ }
+
+ // here we initialize all the data to eventFragment layout and return the View
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
+ LayoutInflater layoutInflater = (LayoutInflater) getActivity().getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ View event = layoutInflater.inflate(R.layout.event, null, false);
+ TextView name = event.findViewById(R.id.textView_name);
+ TextView date = event.findViewById(R.id.textView_date);
+ TextView description = event.findViewById(R.id.textView_description);
+ TextView place = event.findViewById(R.id.textView_place);
+
+ name.setText(EventsController.getEvent(getArguments().getInt("index",0)).getEventName());
+ date.setText(EventsController.getEvent(getArguments().getInt("index",0)).getEventDate());
+ description.setText(EventsController.getEvent(getArguments().getInt("index",0)).getEventDescription());
+ place.setText(EventsController.getEvent(getArguments().getInt("index",0)).getEventPlace());
+
+ return event;
+ }
+}
+
diff --git a/app/src/main/java/com/example/webapplicationwithspring/Events/Event.java b/app/src/main/java/com/example/webapplicationwithspring/Events/Event.java
new file mode 100644
index 0000000..9acdaad
--- /dev/null
+++ b/app/src/main/java/com/example/webapplicationwithspring/Events/Event.java
@@ -0,0 +1,59 @@
+package com.example.webapplicationwithspring.Events;
+
+public class Event {
+ private String eventName;
+ private String eventDate;
+ private String eventDescription;
+ private String eventPlace;
+ private int id;
+
+
+
+ public Event(String eventName, String eventDate, String eventDescription, String eventPlace, int id) {
+ this.eventName = eventName;
+ this.eventDate = eventDate;
+ this.eventDescription = eventDescription;
+ this.eventPlace = eventPlace;
+ this.id = id;
+ }
+
+ public String getEventName() {
+ return eventName;
+ }
+
+ public void setEventName(String eventName) {
+ this.eventName = eventName;
+ }
+
+ public String getEventDate() {
+ return eventDate;
+ }
+
+ public void setEventDate(String eventDate) {
+ this.eventDate = eventDate;
+ }
+
+ public String getEventDescription() {
+ return eventDescription;
+ }
+
+ public void setEventDescription(String eventDescription) {
+ this.eventDescription = eventDescription;
+ }
+
+ public String getEventPlace() {
+ return eventPlace;
+ }
+
+ public void setEventPlace(String eventPlace) {
+ this.eventPlace = eventPlace;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+}
diff --git a/app/src/main/java/com/example/webapplicationwithspring/Events/EventsController.java b/app/src/main/java/com/example/webapplicationwithspring/Events/EventsController.java
new file mode 100644
index 0000000..ed3230d
--- /dev/null
+++ b/app/src/main/java/com/example/webapplicationwithspring/Events/EventsController.java
@@ -0,0 +1,21 @@
+package com.example.webapplicationwithspring.Events;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+public class EventsController {
+ private static Map eventsMap= new HashMap();
+ public static void addEvent(String eventName, String eventDate, String eventDescription, String eventPlace, int id){
+ eventsMap.put(id, new Event(eventName,eventDate,eventDescription,eventPlace,id));
+ }
+ public static Event getEvent(int index){
+ return eventsMap.get(index);
+ }
+ public static Collection getValue(){
+ return eventsMap.values();
+ }
+ public static int getSize(){ return eventsMap.size(); }
+
+}
+
diff --git a/app/src/main/java/com/example/webapplicationwithspring/Events/Place.java b/app/src/main/java/com/example/webapplicationwithspring/Events/Place.java
new file mode 100644
index 0000000..774113b
--- /dev/null
+++ b/app/src/main/java/com/example/webapplicationwithspring/Events/Place.java
@@ -0,0 +1,80 @@
+package com.example.webapplicationwithspring.Events;
+
+public class Place {
+ private String location;
+ private String name;
+ private String description;
+ private String workHours;
+ private String address;
+ private String telegram;
+ private String phoneNumber;
+ private int id;
+
+ public Place(String name, String location, String description, String workHours,String address, String telegram, String phoneNumber, int id) {
+ this.location = location;
+ this.name = name;
+ this.description = description;
+ this.workHours = workHours;
+ this.address = address;
+ this.telegram = telegram;
+ this.phoneNumber = phoneNumber;
+ this.id = id;
+
+ }
+
+ public String getLocation() {
+ return location;
+ }
+
+ public void setLocation(String location) {
+ this.location = location;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getWorkHours() {
+ return workHours;
+ }
+
+ public void setWorkHours(String workHours) {
+ this.workHours = workHours;
+ }
+
+ public String getAddress() {
+ return address;
+ }
+
+ public void setAddress(String adress) {
+ this.address = adress;
+ }
+
+ public String getTelegram() {
+ return telegram;
+ }
+
+ public void setTelegram(String telegram) {
+ this.telegram = telegram;
+ }
+
+ public String getPhoneNumber() {
+ return phoneNumber;
+ }
+
+ public void setPhoneNumber(String phoneNumber) {
+ this.phoneNumber = phoneNumber;
+ }
+}
diff --git a/app/src/main/java/com/example/webapplicationwithspring/Events/PlacesController.java b/app/src/main/java/com/example/webapplicationwithspring/Events/PlacesController.java
new file mode 100644
index 0000000..76c65ed
--- /dev/null
+++ b/app/src/main/java/com/example/webapplicationwithspring/Events/PlacesController.java
@@ -0,0 +1,20 @@
+package com.example.webapplicationwithspring.Events;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+public class PlacesController {
+ public static Map placesMap = new HashMap();
+ public static void addEvent(String name, String location, String description, String workHours,String address, String telegram, String phoneNumbe, int id){
+ placesMap.put(id, new Place(name, location,description,workHours,address,telegram,phoneNumbe,id));
+ }
+ public static Place getPlace(int index){
+ return placesMap.get(index);
+ }
+ public static Collection getValue(){
+ return placesMap.values();
+ }
+ public static int getSize(){ return placesMap.size(); }
+
+}
diff --git a/app/src/main/java/com/example/webapplicationwithspring/EventsActivity.java b/app/src/main/java/com/example/webapplicationwithspring/EventsActivity.java
new file mode 100644
index 0000000..3d284b6
--- /dev/null
+++ b/app/src/main/java/com/example/webapplicationwithspring/EventsActivity.java
@@ -0,0 +1,238 @@
+package com.example.webapplicationwithspring;
+
+import android.app.FragmentManager;
+import android.app.FragmentTransaction;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.FrameLayout;
+import android.widget.LinearLayout;
+import android.widget.ListView;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import androidx.activity.OnBackPressedCallback;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.appcompat.app.AppCompatActivity;
+
+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.JsonArrayRequest;
+import com.android.volley.toolbox.Volley;
+import com.example.webapplicationwithspring.Events.Event;
+import com.example.webapplicationwithspring.Events.EventsController;
+import com.google.android.material.bottomnavigation.BottomNavigationView;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class EventsActivity extends AppCompatActivity {
+ private ListView listView;
+ private boolean refreshed = false;
+ // adapter and fragment manager initialization, we will need them for
+ // displaying the Event data in the list
+ // Switching between the fragment when some event is clicked
+ MyAdapter adapter;
+ FragmentManager fragmentManager = getFragmentManager();
+ // url for local server
+ //private String url = "http://192.168.0.119:8080/eventsList";
+ private String url = "http://172.20.10.12:8080/eventsList";
+ // this will switch between items in the navigation bar;
+ private BottomNavigationView.OnNavigationItemSelectedListener navListener =
+ new BottomNavigationView.OnNavigationItemSelectedListener() {
+ @Override
+ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
+
+ /* define the logic to switch between the fragments in navigation bar */
+ switch (item.getItemId()) {
+ case R.id.nav_events: {
+ Toast.makeText(getApplicationContext(), "You are going to open events fragment", Toast.LENGTH_SHORT).show();
+ break;
+ }
+ case R.id.nav_profile: {
+
+ Toast.makeText(getApplicationContext(), "You are going to open profile fragment", Toast.LENGTH_SHORT).show();
+ break;
+ }
+ case R.id.nav_map: {
+ // when we meet new item to be selected we switch to new activity
+ Toast.makeText(getApplicationContext(), "You are already in the Map", Toast.LENGTH_SHORT).show();
+ startActivity(new Intent(getApplicationContext(), MapActivity.class));
+ overridePendingTransition(0, 0);
+ break;
+ }
+ }
+ return true;
+ }
+ };
+
+ @Override
+ public void onCreate(@Nullable Bundle savedInstanceState) {
+ // set thr activity to the last saved state
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_events);
+ //
+ listView = findViewById(R.id.list_view);
+ listView.setItemsCanFocus(false);
+ listView.setClickable(true);
+ // When some particular event is clicked in the list the following method is called
+ listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView> parent, View view, int position, long id) {
+ // for debagging
+ Toast.makeText(EventsActivity.this, "you clicked item" + position + "long press" + id, Toast.LENGTH_SHORT).show();
+ // show details about the fragment, the fragment manager will be called
+ showDetails(position);
+ }
+ });
+
+ // displaying data extracted from the server
+ if (EventsController.getSize() != 0 && !refreshed) {
+ String[] titles = new String[EventsController.getSize()];
+ String[] descriptions = new String[EventsController.getSize()];
+ for (Event e : EventsController.getValue()) {
+ titles[e.getId()] = e.getEventName();
+ descriptions[e.getId()] = e.getEventDescription();
+ }
+ MyAdapter adapter = new MyAdapter(this, titles, descriptions);
+ listView.setAdapter(adapter);
+ } else {
+ // make a response to server to store the data
+ RequestQueue requestQueue = Volley.newRequestQueue(this);
+ // initialize the ArrayRequest and set value to the EventContoller Map
+ JsonArrayRequest objectRequest = new JsonArrayRequest(
+ Request.Method.GET,
+ url,
+ null,
+ new Response.Listener() {
+ @Override
+ public void onResponse(JSONArray response) {
+ List titles = new ArrayList();
+ List descriptions = new ArrayList();
+ try {
+ for (int i = 0; i < response.length(); i++) {
+ JSONObject jo = (JSONObject) response.get(i);
+ String eventName = jo.getString("eventName");
+ String eventDate = jo.getString("eventDate");
+ String eventDescription = jo.getString("eventDescription");
+ String eventPlace = jo.getString("eventPlace");
+ EventsController.addEvent(eventName, eventDate, eventDescription, eventPlace, Integer.parseInt(jo.getString("id")));
+ titles.add(eventName);
+ descriptions.add(eventDescription);
+ }
+ adapter = new MyAdapter(EventsActivity.this, titles.toArray(new String[titles.size()]), descriptions.toArray(new String[descriptions.size()]));
+ listView.setAdapter(adapter);
+ } catch (JSONException e) {
+ //View errorView = getTextView(EventsActivity.this, "Server does not response");
+
+ //listView.addHeaderView(errorView);
+ e.printStackTrace();
+ }
+ }
+ },
+ new Response.ErrorListener() {
+ @Override
+ public void onErrorResponse(VolleyError error) {
+ TextView tv = getTextView(EventsActivity.this, "Server does not response");
+ FrameLayout frameLayout = findViewById(R.id.fragment_container);
+ frameLayout.addView(tv);
+ Log.d("EventSSS", error.toString());
+ }
+ }
+ );
+ requestQueue.add(objectRequest);
+ }
+
+
+ // On back button click action
+ OnBackPressedCallback callback = new OnBackPressedCallback(true /* enabled by default */) {
+ @Override
+ public void handleOnBackPressed() {
+ if(listView.getVisibility() == View.INVISIBLE){
+ listView.setVisibility(View.VISIBLE);
+ fragmentManager.beginTransaction().remove(fragmentManager.findFragmentById(R.id.fragment_container)).commit();
+ }
+ // Handle the back button event
+ }
+ };
+ getOnBackPressedDispatcher().addCallback(this, callback);
+
+
+// set the bottom navigation bar to switch between activities
+ BottomNavigationView nView = findViewById(R.id.bottom_navigation_for_events);
+ nView.setOnNavigationItemSelectedListener(navListener);
+ nView.setSelectedItemId(R.id.nav_events);
+ }
+
+ public TextView getTextView(Context context, String text) {
+ final TextView tv = new TextView(context);
+ tv.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
+ tv.setTextSize(30);
+ tv.setText(text);
+ //final FragmentManager manager = getSupportFragmentManager();
+ tv.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ //manager.beginTransaction().replace(R.id.scroll_layout, new BlankFragment()).commit();
+ Toast.makeText(EventsActivity.this, "you have clicked on event", Toast.LENGTH_SHORT).show();
+ }
+ });
+ return tv;
+
+ }
+
+
+ // when the idem is clicked details have to be shown
+ private void showDetails(int index) {
+ listView.setItemChecked(index, true);
+ EventFragment eventFragment = EventFragment.newInstance(index);
+ FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
+ fragmentTransaction.replace(R.id.fragment_container, eventFragment);
+ fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
+ fragmentTransaction.commit();
+ listView.setVisibility(View.INVISIBLE);
+ }
+ // customized array adapter is needed for proper data visualization
+ class MyAdapter extends ArrayAdapter {
+ Context context;
+ String rTitle[];
+ String rDescription[];
+ //int rImage[];
+
+ public MyAdapter(@NonNull Context context, String[] title, String[] description) {
+ super(context, R.layout.row, R.id.text_viewTitle, title);
+ this.context = context;
+ // events = eventsCol.toArray(new Event[eventsCol.size()]);
+ this.rTitle = title;
+ this.rDescription = description;
+ // this.rImage = Images;
+ }
+
+ @NonNull
+ @Override
+ public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
+ LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ View row = layoutInflater.inflate(R.layout.row, parent, false);
+ TextView titleView = row.findViewById(R.id.text_viewTitle);
+ TextView descriptionView = row.findViewById(R.id.text_viewDescription);
+
+ titleView.setText(rTitle[position]);
+ descriptionView.setText(rDescription[position]);
+ return row;
+ }
+ }
+}
diff --git a/app/src/main/java/com/example/webapplicationwithspring/MainActivity.java b/app/src/main/java/com/example/webapplicationwithspring/MainActivity.java
index b95b5fd..4686e19 100644
--- a/app/src/main/java/com/example/webapplicationwithspring/MainActivity.java
+++ b/app/src/main/java/com/example/webapplicationwithspring/MainActivity.java
@@ -1,21 +1,25 @@
package com.example.webapplicationwithspring;
-import androidx.appcompat.app.AppCompatActivity;
-
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
+import android.widget.EditText;
import android.widget.Toast;
+import androidx.appcompat.app.AppCompatActivity;
+
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.maps.GoogleMap;
public class MainActivity extends AppCompatActivity {
+ // private EditText emailEditText = findViewById(R.id.login_Email);
+// private EditText passwordEditText = findViewById(R.id.login_Password);
+
GoogleMap map;
private static final String TAG = "MainActivity";
private static final int ERROR = 9001;
@@ -34,22 +38,26 @@ private void init(){
buttonMap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
+ // String email = emailEditText.getText().toString();
+ // String password = passwordEditText.getText().toString();
+
Intent intent = new Intent(MainActivity.this, MapActivity.class);
startActivity(intent);
}
});
+
}
private boolean isServicesOK(){
- Log.d(TAG,"isServiceOK: check goole services version" );
+ Log.d(TAG,"isServiceOK: check google services version" );
int available = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(MainActivity.this);
if(available == ConnectionResult.SUCCESS){
Log.d(TAG,"isServiceOK: Services works ok");
return true;
} else if(GoogleApiAvailability.getInstance().isUserResolvableError(available)){
- Log.d(TAG, "error occured");
+ Log.d(TAG, "error occurred");
Dialog dialog = GoogleApiAvailability.getInstance().getErrorDialog(MainActivity.this, available, ERROR);
dialog.show();
} else {
diff --git a/app/src/main/java/com/example/webapplicationwithspring/MapActivity.java b/app/src/main/java/com/example/webapplicationwithspring/MapActivity.java
index aa28c8d..bc97782 100644
--- a/app/src/main/java/com/example/webapplicationwithspring/MapActivity.java
+++ b/app/src/main/java/com/example/webapplicationwithspring/MapActivity.java
@@ -1,13 +1,22 @@
package com.example.webapplicationwithspring;
import android.Manifest;
-import android.app.Activity;
-import android.app.AppComponentFactory;
-import android.content.Context;
+import android.content.Intent;
import android.content.pm.PackageManager;
+import android.location.Address;
+import android.location.Geocoder;
+import android.location.Location;
import android.os.Bundle;
import android.util.Log;
+import android.view.KeyEvent;
import android.view.MenuItem;
+import android.view.View;
+import android.view.WindowManager;
+import android.view.inputmethod.EditorInfo;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.ImageView;
+import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
@@ -15,38 +24,60 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
-import androidx.fragment.app.Fragment;
+import com.example.webapplicationwithspring.directionhelpers.FetchURL;
+import com.example.webapplicationwithspring.directionhelpers.TaskLoadedCallback;
+import com.google.android.gms.location.FusedLocationProviderClient;
+import com.google.android.gms.location.LocationServices;
+import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
+import com.google.android.gms.maps.model.LatLng;
+import com.google.android.gms.maps.model.MarkerOptions;
+import com.google.android.gms.maps.model.Polyline;
+import com.google.android.gms.maps.model.PolylineOptions;
+import com.google.android.gms.tasks.OnCompleteListener;
+import com.google.android.gms.tasks.Task;
import com.google.android.material.bottomnavigation.BottomNavigationView;
-public class MapActivity extends AppCompatActivity implements OnMapReadyCallback{
+import org.json.JSONArray;
+import org.json.JSONObject;
- private static final String TAG = "MapActivity";
- private static final String FINE_LOCATION = Manifest.permission.ACCESS_FINE_LOCATION;
- private static final String COARSE_LOCATION = Manifest.permission.ACCESS_COARSE_LOCATION;
- private Boolean mLocationPermissionGranted = false;
- private static final int L_PERMISSION_REQUEST_CODE = 1234;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+public class MapActivity extends AppCompatActivity implements OnMapReadyCallback, TaskLoadedCallback {
+// define tags and permission strings
+ //private static final String TAG = "MapActivity";
+ //private static final String FINE_LOCATION = Manifest.permission.ACCESS_FINE_LOCATION;
+ //private static final String COARSE_LOCATION = Manifest.permission.ACCESS_COARSE_LOCATION;
+ //private Boolean mLocationPermissionGranted = false;
+ //private static final int L_PERMISSION_REQUEST_CODE = 1234;
+ // this will switch between items in the navigation bar
private BottomNavigationView.OnNavigationItemSelectedListener navListener =
new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
- Fragment selectedFrag = null;
+
// define the logic to switch between the fragments in navigation bar
switch (item.getItemId()){
case R.id.nav_events: {
+ // when the new item was clicked we switch an activity
Toast.makeText(getApplicationContext(), "You are going to open events fragment", Toast.LENGTH_SHORT).show();
+ startActivity(new Intent(getApplicationContext(), EventsActivity.class));
+ overridePendingTransition(0,0);
+
break;
}
case R.id.nav_profile:{
+
Toast.makeText(getApplicationContext(), "You are going to open profile fragment", Toast.LENGTH_SHORT).show();
break;
}
case R.id.nav_map:{
- Toast.makeText(getApplicationContext(), "You are going to open the Map", Toast.LENGTH_SHORT).show();
+ Toast.makeText(getApplicationContext(), "You are already in the Map", Toast.LENGTH_SHORT).show();
break;
}
}
@@ -56,60 +87,298 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
private GoogleMap gMap;
@Override
- public void onCreate(@Nullable Bundle savedInstanceState){
+ public void onMapReady(GoogleMap googleMap) {
+ Toast.makeText(this, "Map is Ready", Toast.LENGTH_SHORT).show();
+ Log.d(TAG, "onMapReady: map is ready");
+ mMap = googleMap;
+
+ if (mLocationPermissionsGranted) {
+ getDeviceLocation();
+
+ if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
+ != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
+ Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
+ return;
+ }
+ mMap.setMyLocationEnabled(true);
+ mMap.getUiSettings().setMyLocationButtonEnabled(false);
+
+ init();
+ }
+
+ mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
+ @Override
+ public void onMapClick(LatLng latLng) {
+ //Creating Marker
+
+ //Set Marker position
+ marker.position(latLng);
+ //Set Latitude and longitude on Marker
+ marker.title(latLng.latitude+" : "+latLng.longitude);
+ //Clear the previously click position
+ mMap.clear();
+ //Zoom the marker
+ mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng,15));
+ //Add marker on Map
+ mMap.addMarker(marker);
+ }
+ });
+
+ }
+
+ private static final String TAG = "MapActivity";
+
+ private static final String FINE_LOCATION = Manifest.permission.ACCESS_FINE_LOCATION;
+ private static final String COURSE_LOCATION = Manifest.permission.ACCESS_COARSE_LOCATION;
+ private static final int LOCATION_PERMISSION_REQUEST_CODE = 1234;
+ private static final float DEFAULT_ZOOM = 15f;
+
+ //widgets
+ private EditText mSearchText;
+ private ImageView mGps;
+
+ //vars
+ private Boolean mLocationPermissionsGranted = false;
+ private GoogleMap mMap;
+ private Button btnDriving;
+ private Button btnWalking;
+ private Button btnBicycling;
+ Location currentLocation;
+ MarkerOptions marker = new MarkerOptions();
+ MarkerOptions current = new MarkerOptions();
+ Polyline currentPolyline;
+ private FusedLocationProviderClient mFusedLocationProviderClient;
+ private LatLng curLoc;
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
+ mSearchText = (EditText) findViewById(R.id.input_search);
+ mGps = (ImageView) findViewById(R.id.ic_gps);
+ btnDriving = findViewById(R.id.driving_btn);
+ btnWalking = findViewById(R.id.Walking_btn);
+ btnBicycling = findViewById(R.id.Bicycling_btn);
+ btnDriving.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ String url = getUrl(marker.getPosition(),current.getPosition(),"driving");
+ FetchURL d = new FetchURL(MapActivity.this);
+ d.execute(url,"driving");
+ Toast.makeText(MapActivity.this, "distance: " + d.distance + " duration" + d.duration, Toast.LENGTH_SHORT).show();
+ }
+ });
+ btnWalking.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ String url = getUrl(marker.getPosition(),current.getPosition(),"walking");
+ FetchURL w = new FetchURL(MapActivity.this);
+ w.execute(url,"walking");
+ Toast.makeText(MapActivity.this, "distance: " + w.distance + " duration" + w.duration, Toast.LENGTH_SHORT).show();
+ }
+ });
+ btnBicycling.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ String url = getUrl(marker.getPosition(),current.getPosition(),"transit");
+ FetchURL t = new FetchURL(MapActivity.this);
+ t.execute(url,"transit");
+ Toast.makeText(MapActivity.this, "distance: " + t.distance + " duration" + t.duration, Toast.LENGTH_SHORT).show();
+ }
+ });
+
getLocationPermission();
+// set the bottom navigation bar to switch between activities
BottomNavigationView nView = findViewById(R.id.bottom_navigation);
nView.setOnNavigationItemSelectedListener(navListener);
+ nView.setSelectedItemId(R.id.nav_map);
+ //getDeviceLocation();
+ //MarkerOptions destination = new MarkerOptions().position(new LatLng(38.567019, -121.508839)).title("destination");
+ //MarkerOptions myLocation = new MarkerOptions().position(curLoc).title("current cocation");
+
+ // String url = getUrl()
+ }
+
+ private void init(){
+ Log.d(TAG, "init: initializing");
+
+ mSearchText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
+ @Override
+ public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
+ if(actionId == EditorInfo.IME_ACTION_SEARCH
+ || actionId == EditorInfo.IME_ACTION_DONE
+ || keyEvent.getAction() == KeyEvent.ACTION_DOWN
+ || keyEvent.getAction() == KeyEvent.KEYCODE_ENTER){
+
+ //execute our method for searching
+ geoLocate();
+ }
+
+ return false;
+ }
+ });
+
+ mGps.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Log.d(TAG, "onClick: clicked gps icon");
+ getDeviceLocation();
+ }
+ });
+
+ hideSoftKeyboard();
+ }
+
+ private void geoLocate(){
+ Log.d(TAG, "geoLocate: geolocating");
+
+ String searchString = mSearchText.getText().toString();
+
+ Geocoder geocoder = new Geocoder(MapActivity.this);
+
+ List list = new ArrayList<>();
+ try{
+ list = geocoder.getFromLocationName(searchString, 1);
+ }catch (IOException e){
+ Log.e(TAG, "geoLocate: IOException: " + e.getMessage() );
+ }
+
+ if(list.size() > 0){
+ Address address = list.get(0);
+
+ Log.d(TAG, "geoLocate: found a location: " + address.toString());
+ //Toast.makeText(this, address.toString(), Toast.LENGTH_SHORT).show();
+
+ moveCamera(new LatLng(address.getLatitude(), address.getLongitude()), DEFAULT_ZOOM,
+ address.getAddressLine(0));
+ }
+ }
+
+ private void getDeviceLocation(){
+ Log.d(TAG, "getDeviceLocation: getting the devices current location");
+
+ mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
+
+ try{
+ if(mLocationPermissionsGranted){
+
+ final Task location = mFusedLocationProviderClient.getLastLocation();
+ location.addOnCompleteListener(new OnCompleteListener() {
+ @Override
+ public void onComplete(@NonNull Task task) {
+ if(task.isSuccessful()){
+ Log.d(TAG, "onComplete: found location!");
+ currentLocation = (Location) task.getResult();
+ curLoc = new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude());
+ moveCamera(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()),
+ DEFAULT_ZOOM,
+ "My Location");
+ current.position(curLoc);
+ Toast.makeText(MapActivity.this, "your location is " + currentLocation.getLatitude() + " " +
+ currentLocation.getLongitude() + " ", Toast.LENGTH_SHORT).show();
+
+ }else{
+ Log.d(TAG, "onComplete: current location is null");
+ Toast.makeText(MapActivity.this, "unable to get current location", Toast.LENGTH_SHORT).show();
+ }
+ }
+ });
+ }
+ }catch (SecurityException e){
+ Log.e(TAG, "getDeviceLocation: SecurityException: " + e.getMessage() );
+ }
+ }
+
+ private void moveCamera(LatLng latLng, float zoom, String title){
+ Log.d(TAG, "moveCamera: moving the camera to: lat: " + latLng.latitude + ", lng: " + latLng.longitude );
+ mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, zoom));
+
+ if(!title.equals("My Location")){
+ MarkerOptions options = new MarkerOptions()
+ .position(latLng)
+ .title(title);
+ mMap.addMarker(options);
+ }
+
+ hideSoftKeyboard();
}
private void initMap(){
- Log.d(TAG, "initMAp : initialization");
+ Log.d(TAG, "initMap: initializing map");
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
+
mapFragment.getMapAsync(MapActivity.this);
}
private void getLocationPermission(){
- Log.d(TAG, "getLocation permission : gettionf location permissions");
- String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION,
- Manifest.permission.ACCESS_FINE_LOCATION};
-
- if(ContextCompat.checkSelfPermission(this.getApplicationContext(), FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){
- if(ContextCompat.checkSelfPermission(this.getApplicationContext(), COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED)
- mLocationPermissionGranted = true;
- else{
- ActivityCompat.requestPermissions(this, permissions, L_PERMISSION_REQUEST_CODE);
+ Log.d(TAG, "getLocationPermission: getting location permissions");
+ String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION,
+ Manifest.permission.ACCESS_COARSE_LOCATION};
+
+ if(ContextCompat.checkSelfPermission(this.getApplicationContext(),
+ FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){
+ if(ContextCompat.checkSelfPermission(this.getApplicationContext(),
+ COURSE_LOCATION) == PackageManager.PERMISSION_GRANTED){
+ mLocationPermissionsGranted = true;
+ initMap();
+ }else{
+ ActivityCompat.requestPermissions(this,
+ permissions,
+ LOCATION_PERMISSION_REQUEST_CODE);
}
+ }else{
+ ActivityCompat.requestPermissions(this,
+ permissions,
+ LOCATION_PERMISSION_REQUEST_CODE);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
- Log.d(TAG, "onRequestPermissionResult : called");
- mLocationPermissionGranted = false;
- switch (requestCode){
- case L_PERMISSION_REQUEST_CODE: {
- if(grantResults.length>0){
- for(int i =0; i < grantResults.length; i++){
+ Log.d(TAG, "onRequestPermissionsResult: called.");
+ mLocationPermissionsGranted = false;
+
+ switch(requestCode){
+ case LOCATION_PERMISSION_REQUEST_CODE:{
+ if(grantResults.length > 0){
+ for(int i = 0; i < grantResults.length; i++){
if(grantResults[i] != PackageManager.PERMISSION_GRANTED){
- mLocationPermissionGranted = false;
- Log.d(TAG, "onRequestPermissionResult : remission failed");
+ mLocationPermissionsGranted = false;
+ Log.d(TAG, "onRequestPermissionsResult: permission failed");
return;
}
}
- Log.d(TAG, "onRequestPermissionResult : remission fgranted");
- mLocationPermissionGranted = true;
+ Log.d(TAG, "onRequestPermissionsResult: permission granted");
+ mLocationPermissionsGranted = true;
+ //initialize our map
initMap();
}
}
}
}
+ private void hideSoftKeyboard(){
+ this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
+ }
+ private String getUrl(LatLng origin, LatLng dest, String directionMode) {
+ // Origin of route
+ String str_origin = "origin=" + origin.latitude + "," + origin.longitude;
+ // Destination of route
+ String str_dest = "destination=" + dest.latitude + "," + dest.longitude;
+ // Mode
+ String mode = "mode=" + directionMode;
+ // Building the parameters to the web service
+ String parameters = str_origin + "&" + str_dest + "&" + mode;
+ // Output format
+ String output = "json";
+ // Building the url to the web service
+ String url = "https://maps.googleapis.com/maps/api/directions/" + output + "?" + parameters + "&key=" +"AIzaSyD4SHywIY-5Z4t_zs1O89Iy9eyvNt2QfdY";
+ return url;
+ }
+
@Override
- public void onMapReady(GoogleMap googleMap) {
- Toast.makeText(this, "Map is ready", Toast.LENGTH_SHORT).show();
- Log.d(TAG, "On map: MAP is ready here");
- gMap = googleMap;
+ public void onTaskDone(Object... values) {
+ if (currentPolyline!=null)
+ currentPolyline.remove();
+ currentPolyline=mMap.addPolyline((PolylineOptions)values[0]);
}
}
diff --git a/app/src/main/java/com/example/webapplicationwithspring/PlacesActivity.java b/app/src/main/java/com/example/webapplicationwithspring/PlacesActivity.java
new file mode 100644
index 0000000..464a42c
--- /dev/null
+++ b/app/src/main/java/com/example/webapplicationwithspring/PlacesActivity.java
@@ -0,0 +1,64 @@
+package com.example.webapplicationwithspring;
+
+import androidx.annotation.NonNull;
+import androidx.appcompat.app.AppCompatActivity;
+
+import android.app.FragmentManager;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.MenuItem;
+import android.widget.ListView;
+import android.widget.Toast;
+
+import com.google.android.material.bottomnavigation.BottomNavigationView;
+
+public class PlacesActivity extends AppCompatActivity {
+
+ private ListView listView;
+
+ EventsActivity.MyAdapter adapter;
+ FragmentManager fragmentManager = getFragmentManager();
+
+ private BottomNavigationView.OnNavigationItemSelectedListener navListener =
+ new BottomNavigationView.OnNavigationItemSelectedListener() {
+ @Override
+ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
+
+ /* define the logic to switch between the fragments in navigation bar */
+ switch (item.getItemId()) {
+ case R.id.nav_events: {
+ Toast.makeText(getApplicationContext(), "You are going to open events fragment", Toast.LENGTH_SHORT).show();
+ break;
+ }
+ case R.id.nav_profile: {
+
+ Toast.makeText(getApplicationContext(), "You are going to open profile fragment", Toast.LENGTH_SHORT).show();
+ break;
+ }
+ case R.id.nav_map: {
+ // when we meet new item to be selected we switch to new activity
+ Toast.makeText(getApplicationContext(), "You are already in the Map", Toast.LENGTH_SHORT).show();
+ startActivity(new Intent(getApplicationContext(), MapActivity.class));
+ overridePendingTransition(0, 0);
+ break;
+ }
+ }
+ return true;
+ }
+ };
+
+
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_places);
+
+
+
+
+ BottomNavigationView nView = findViewById(R.id.bottom_navigation_for_events);
+ nView.setOnNavigationItemSelectedListener(navListener);
+ nView.setSelectedItemId(R.id.nav_events);
+ }
+}
diff --git a/app/src/main/java/com/example/webapplicationwithspring/directionhelpers/DataParser.java b/app/src/main/java/com/example/webapplicationwithspring/directionhelpers/DataParser.java
new file mode 100644
index 0000000..0ffcc08
--- /dev/null
+++ b/app/src/main/java/com/example/webapplicationwithspring/directionhelpers/DataParser.java
@@ -0,0 +1,100 @@
+package com.example.webapplicationwithspring.directionhelpers;
+
+
+import android.nfc.Tag;
+import android.util.Log;
+
+import com.google.android.gms.maps.model.LatLng;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+
+
+public class DataParser {
+ public List>> parse(JSONObject jObject) {
+
+ List>> routes = new ArrayList<>();
+ JSONArray jRoutes;
+ JSONArray jLegs;
+ JSONArray jSteps;
+ try {
+ jRoutes = jObject.getJSONArray("routes");
+ /** Traversing all routes */
+ for (int i = 0; i < jRoutes.length(); i++) {
+ jLegs = ((JSONObject) jRoutes.get(i)).getJSONArray("legs");
+ List path = new ArrayList<>();
+ /** Traversing all legs */
+ for (int j = 0; j < jLegs.length(); j++) {
+ jSteps = ((JSONObject) jLegs.get(j)).getJSONArray("steps");
+
+ /** Traversing all steps */
+ for (int k = 0; k < jSteps.length(); k++) {
+ String polyline = "";
+ polyline = (String) ((JSONObject) ((JSONObject) jSteps.get(k)).get("polyline")).get("points");
+ List list = decodePoly(polyline);
+
+ /** Traversing all points */
+ for (int l = 0; l < list.size(); l++) {
+ HashMap hm = new HashMap<>();
+ hm.put("lat", Double.toString((list.get(l)).latitude));
+ hm.put("lng", Double.toString((list.get(l)).longitude));
+ path.add(hm);
+
+ }
+ }
+ routes.add(path);
+ }
+ }
+
+ } catch (JSONException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
+ }
+ return routes;
+ }
+
+
+ /**
+ * Method to decode polyline points
+ * Courtesy : https://jeffreysambells.com/2010/05/27/decoding-polylines-from-google-maps-direction-api-with-java
+ */
+ private List decodePoly(String encoded) {
+
+ List poly = new ArrayList<>();
+ int index = 0, len = encoded.length();
+ int lat = 0, lng = 0;
+
+ while (index < len) {
+ int b, shift = 0, result = 0;
+ do {
+ b = encoded.charAt(index++) - 63;
+ result |= (b & 0x1f) << shift;
+ shift += 5;
+ } while (b >= 0x20);
+ int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
+ lat += dlat;
+
+ shift = 0;
+ result = 0;
+ do {
+ b = encoded.charAt(index++) - 63;
+ result |= (b & 0x1f) << shift;
+ shift += 5;
+ } while (b >= 0x20);
+ int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
+ lng += dlng;
+
+ LatLng p = new LatLng((((double) lat / 1E5)),
+ (((double) lng / 1E5)));
+ poly.add(p);
+ }
+
+ return poly;
+ }
+}
diff --git a/app/src/main/java/com/example/webapplicationwithspring/directionhelpers/FetchURL.java b/app/src/main/java/com/example/webapplicationwithspring/directionhelpers/FetchURL.java
new file mode 100644
index 0000000..daa702f
--- /dev/null
+++ b/app/src/main/java/com/example/webapplicationwithspring/directionhelpers/FetchURL.java
@@ -0,0 +1,111 @@
+package com.example.webapplicationwithspring.directionhelpers;
+
+
+import android.content.Context;
+import android.os.AsyncTask;
+import android.util.Log;
+import android.widget.Toast;
+
+import com.example.webapplicationwithspring.MapActivity;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+
+public class FetchURL extends AsyncTask {
+ Context mContext;
+ String directionMode = "driving";
+ public static String distance;
+ public static String duration ;
+
+ public FetchURL(Context mContext) {
+ this.mContext = mContext;
+ }
+
+ @Override
+ protected String doInBackground(String... strings) {
+ // For storing data from web service
+ String data = "";
+ directionMode = strings[1];
+ try {
+ // Fetching the data from web service
+ data = downloadUrl(strings[0]);
+ Log.d("mylog", "Background task data " + data.toString());
+ } catch (Exception e) {
+ Log.d("Background Task", e.toString());
+ }
+ return data;
+ }
+
+ @Override
+ protected void onPostExecute(String s) {
+ super.onPostExecute(s);
+ PointsParser parserTask = new PointsParser(mContext, directionMode);
+ // Invokes the thread for parsing the JSON data
+ parserTask.execute(s);
+ }
+
+ private String downloadUrl(String strUrl) throws IOException {
+ String data = "";
+ InputStream iStream = null;
+ HttpURLConnection urlConnection = null;
+ try {
+ URL url = new URL(strUrl);
+ // Creating an http connection to communicate with url
+ urlConnection = (HttpURLConnection) url.openConnection();
+ // Connecting to url
+ urlConnection.connect();
+ // Reading data from url
+ iStream = urlConnection.getInputStream();
+ BufferedReader br = new BufferedReader(new InputStreamReader(iStream));
+ StringBuffer sb = new StringBuffer();
+ String line = "";
+ while ((line = br.readLine()) != null) {
+ sb.append(line);
+ }
+ data = sb.toString();
+ Log.d("mylog", "Downloaded URL: " + data.toString());
+
+ for (int i=0;i>>> {
+ TaskLoadedCallback taskCallback;
+ String directionMode = "driving";
+
+ public PointsParser(Context mContext, String directionMode) {
+ this.taskCallback = (TaskLoadedCallback) mContext;
+ this.directionMode = directionMode;
+ }
+
+ // Parsing the data in non-ui thread
+ @Override
+ protected List>> doInBackground(String... jsonData) {
+
+ JSONObject jObject;
+ List>> routes = null;
+
+ try {
+ jObject = new JSONObject(jsonData[0]);
+ Log.d("mylog", jsonData[0].toString());
+ DataParser parser = new DataParser();
+ Log.d("mylog", parser.toString());
+
+ // Starts parsing data
+ routes = parser.parse(jObject);
+ Log.d("mylog", "Executing routes");
+ Log.d("mylog", routes.toString());
+
+ } catch (Exception e) {
+ Log.d("mylog", e.toString());
+ e.printStackTrace();
+ }
+ return routes;
+ }
+
+ // Executes in UI thread, after the parsing process
+ @Override
+ protected void onPostExecute(List>> result) {
+ ArrayList points;
+ PolylineOptions lineOptions = null;
+ // Traversing through all the routes
+ for (int i = 0; i < result.size(); i++) {
+ points = new ArrayList<>();
+ lineOptions = new PolylineOptions();
+ // Fetching i-th route
+ List> path = result.get(i);
+ // Fetching all the points in i-th route
+ for (int j = 0; j < path.size(); j++) {
+ HashMap point = path.get(j);
+ double lat = Double.parseDouble(point.get("lat"));
+ double lng = Double.parseDouble(point.get("lng"));
+ LatLng position = new LatLng(lat, lng);
+ points.add(position);
+ }
+ // Adding all the points in the route to LineOptions
+ lineOptions.addAll(points);
+ if (directionMode.equalsIgnoreCase("walking")) {
+ lineOptions.width(10);
+ lineOptions.color(Color.MAGENTA);
+ } else {
+ lineOptions.width(20);
+ lineOptions.color(Color.BLUE);
+ }
+ Log.d("mylog", "onPostExecute lineoptions decoded");
+ }
+
+ // Drawing polyline in the Google Map for the i-th route
+ if (lineOptions != null) {
+ //mMap.addPolyline(lineOptions);
+ taskCallback.onTaskDone(lineOptions);
+
+ } else {
+ Log.d("mylog", "without Polylines drawn");
+ }
+ }
+}
diff --git a/app/src/main/java/com/example/webapplicationwithspring/directionhelpers/TaskLoadedCallback.java b/app/src/main/java/com/example/webapplicationwithspring/directionhelpers/TaskLoadedCallback.java
new file mode 100644
index 0000000..0fbcb46
--- /dev/null
+++ b/app/src/main/java/com/example/webapplicationwithspring/directionhelpers/TaskLoadedCallback.java
@@ -0,0 +1,5 @@
+package com.example.webapplicationwithspring.directionhelpers;
+
+public interface TaskLoadedCallback {
+ void onTaskDone(Object... values);
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/webapplicationwithspring/ui/dashboard/DashboardFragment.java b/app/src/main/java/com/example/webapplicationwithspring/ui/dashboard/DashboardFragment.java
deleted file mode 100644
index 8b9011f..0000000
--- a/app/src/main/java/com/example/webapplicationwithspring/ui/dashboard/DashboardFragment.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.example.webapplicationwithspring.ui.dashboard;
-
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.TextView;
-
-import androidx.annotation.Nullable;
-import androidx.annotation.NonNull;
-import androidx.fragment.app.Fragment;
-import androidx.lifecycle.Observer;
-import androidx.lifecycle.ViewModelProviders;
-
-import com.example.webapplicationwithspring.R;
-
-public class DashboardFragment extends Fragment {
-
- private DashboardViewModel dashboardViewModel;
-
- public View onCreateView(@NonNull LayoutInflater inflater,
- ViewGroup container, Bundle savedInstanceState) {
- dashboardViewModel =
- ViewModelProviders.of(this).get(DashboardViewModel.class);
- View root = inflater.inflate(R.layout.fragment_dashboard, container, false);
- final TextView textView = root.findViewById(R.id.text_dashboard);
- dashboardViewModel.getText().observe(this, new Observer() {
- @Override
- public void onChanged(@Nullable String s) {
- textView.setText(s);
- }
- });
- return root;
- }
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/webapplicationwithspring/ui/dashboard/DashboardViewModel.java b/app/src/main/java/com/example/webapplicationwithspring/ui/dashboard/DashboardViewModel.java
deleted file mode 100644
index b406a0e..0000000
--- a/app/src/main/java/com/example/webapplicationwithspring/ui/dashboard/DashboardViewModel.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.example.webapplicationwithspring.ui.dashboard;
-
-import androidx.lifecycle.LiveData;
-import androidx.lifecycle.MutableLiveData;
-import androidx.lifecycle.ViewModel;
-
-public class DashboardViewModel extends ViewModel {
-
- private MutableLiveData mText;
-
- public DashboardViewModel() {
- mText = new MutableLiveData<>();
- mText.setValue("This is dashboard fragment");
- }
-
- public LiveData getText() {
- return mText;
- }
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/webapplicationwithspring/ui/home/HomeFragment.java b/app/src/main/java/com/example/webapplicationwithspring/ui/home/HomeFragment.java
deleted file mode 100644
index 1f5cf94..0000000
--- a/app/src/main/java/com/example/webapplicationwithspring/ui/home/HomeFragment.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package com.example.webapplicationwithspring.ui.home;
-
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.TextView;
-
-import androidx.annotation.Nullable;
-import androidx.annotation.NonNull;
-import androidx.fragment.app.Fragment;
-import androidx.lifecycle.Observer;
-import androidx.lifecycle.ViewModelProviders;
-
-import com.example.webapplicationwithspring.R;
-
-public class HomeFragment extends Fragment {
-/*
- private HomeViewModel homeViewModel;
-
- public View onCreateView(@NonNull LayoutInflater inflater,
- ViewGroup container, Bundle savedInstanceState) {
- homeViewModel =
- ViewModelProviders.of(this).get(HomeViewModel.class);
- View root = inflater.inflate(R.layout.fragment_home, container, false);
- final TextView textView = root.findViewById(R.id.text_home);
- homeViewModel.getText().observe(this, new Observer() {
- @Override
- public void onChanged(@Nullable String s) {
- textView.setText(s);
- }
- });
- return root;
- }
-
- */
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/webapplicationwithspring/ui/home/HomeViewModel.java b/app/src/main/java/com/example/webapplicationwithspring/ui/home/HomeViewModel.java
deleted file mode 100644
index 042aecc..0000000
--- a/app/src/main/java/com/example/webapplicationwithspring/ui/home/HomeViewModel.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.example.webapplicationwithspring.ui.home;
-
-import androidx.lifecycle.LiveData;
-import androidx.lifecycle.MutableLiveData;
-import androidx.lifecycle.ViewModel;
-
-public class HomeViewModel extends ViewModel {
-
- private MutableLiveData mText;
-
- public HomeViewModel() {
- mText = new MutableLiveData<>();
- mText.setValue("This is home fragment");
- }
-
- public LiveData getText() {
- return mText;
- }
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/webapplicationwithspring/ui/notifications/NotificationsFragment.java b/app/src/main/java/com/example/webapplicationwithspring/ui/notifications/NotificationsFragment.java
deleted file mode 100644
index 29b5a2b..0000000
--- a/app/src/main/java/com/example/webapplicationwithspring/ui/notifications/NotificationsFragment.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.example.webapplicationwithspring.ui.notifications;
-
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.TextView;
-
-import androidx.annotation.Nullable;
-import androidx.annotation.NonNull;
-import androidx.fragment.app.Fragment;
-import androidx.lifecycle.Observer;
-import androidx.lifecycle.ViewModelProviders;
-
-import com.example.webapplicationwithspring.R;
-
-public class NotificationsFragment extends Fragment {
-
- private NotificationsViewModel notificationsViewModel;
-
- public View onCreateView(@NonNull LayoutInflater inflater,
- ViewGroup container, Bundle savedInstanceState) {
- notificationsViewModel =
- ViewModelProviders.of(this).get(NotificationsViewModel.class);
- View root = inflater.inflate(R.layout.fragment_notifications, container, false);
- final TextView textView = root.findViewById(R.id.text_notifications);
- notificationsViewModel.getText().observe(this, new Observer() {
- @Override
- public void onChanged(@Nullable String s) {
- textView.setText(s);
- }
- });
- return root;
- }
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/webapplicationwithspring/ui/notifications/NotificationsViewModel.java b/app/src/main/java/com/example/webapplicationwithspring/ui/notifications/NotificationsViewModel.java
deleted file mode 100644
index da44dc1..0000000
--- a/app/src/main/java/com/example/webapplicationwithspring/ui/notifications/NotificationsViewModel.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.example.webapplicationwithspring.ui.notifications;
-
-import androidx.lifecycle.LiveData;
-import androidx.lifecycle.MutableLiveData;
-import androidx.lifecycle.ViewModel;
-
-public class NotificationsViewModel extends ViewModel {
-
- private MutableLiveData mText;
-
- public NotificationsViewModel() {
- mText = new MutableLiveData<>();
- mText.setValue("This is notifications fragment");
- }
-
- public LiveData getText() {
- return mText;
- }
-}
\ No newline at end of file
diff --git a/app/src/main/res/drawable/ic_gps_fixed_black_24dp.xml b/app/src/main/res/drawable/ic_gps_fixed_black_24dp.xml
new file mode 100644
index 0000000..07d6e46
--- /dev/null
+++ b/app/src/main/res/drawable/ic_gps_fixed_black_24dp.xml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/app/src/main/res/drawable/ic_room_black_24dp.xml b/app/src/main/res/drawable/ic_room_black_24dp.xml
new file mode 100644
index 0000000..e3291a9
--- /dev/null
+++ b/app/src/main/res/drawable/ic_room_black_24dp.xml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/app/src/main/res/drawable/ic_search_black_24dp.xml b/app/src/main/res/drawable/ic_search_black_24dp.xml
new file mode 100644
index 0000000..affc7ba
--- /dev/null
+++ b/app/src/main/res/drawable/ic_search_black_24dp.xml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/app/src/main/res/drawable/white_border.xml b/app/src/main/res/drawable/white_border.xml
new file mode 100644
index 0000000..76276a8
--- /dev/null
+++ b/app/src/main/res/drawable/white_border.xml
@@ -0,0 +1,11 @@
+
+
+
+ -
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_events.xml b/app/src/main/res/layout/activity_events.xml
new file mode 100644
index 0000000..3685da9
--- /dev/null
+++ b/app/src/main/res/layout/activity_events.xml
@@ -0,0 +1,54 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 20d7eaf..92c1808 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -9,17 +9,47 @@
tools:context=".MainActivity">
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_map.xml b/app/src/main/res/layout/activity_map.xml
index c9de9c3..c2b56b8 100644
--- a/app/src/main/res/layout/activity_map.xml
+++ b/app/src/main/res/layout/activity_map.xml
@@ -1,5 +1,6 @@
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
\ No newline at end of file
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_places.xml b/app/src/main/res/layout/activity_places.xml
new file mode 100644
index 0000000..339bb17
--- /dev/null
+++ b/app/src/main/res/layout/activity_places.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/event.xml b/app/src/main/res/layout/event.xml
new file mode 100644
index 0000000..57cafb4
--- /dev/null
+++ b/app/src/main/res/layout/event.xml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_dashboard.xml b/app/src/main/res/layout/fragment_dashboard.xml
deleted file mode 100644
index cc8e4dc..0000000
--- a/app/src/main/res/layout/fragment_dashboard.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml
deleted file mode 100644
index ca5e68a..0000000
--- a/app/src/main/res/layout/fragment_home.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_notifications.xml b/app/src/main/res/layout/fragment_notifications.xml
deleted file mode 100644
index 69bb426..0000000
--- a/app/src/main/res/layout/fragment_notifications.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/layout/row.xml b/app/src/main/res/layout/row.xml
new file mode 100644
index 0000000..4eba2dc
--- /dev/null
+++ b/app/src/main/res/layout/row.xml
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/menu/bottom_navigation.xml b/app/src/main/res/menu/bottom_navigation.xml
index 35f9259..6fa8d4e 100644
--- a/app/src/main/res/menu/bottom_navigation.xml
+++ b/app/src/main/res/menu/bottom_navigation.xml
@@ -10,6 +10,12 @@
android:icon="@drawable/ic_event_black_24dp"
android:title="Events"
android:enabled="true"/>
+
+
- Home
Dashboard
Notifications
+ Get Direction
+
+ Driving
+ Walking
+ Bicycling
diff --git a/app/src/main/res/xml/network_security_config.xml b/app/src/main/res/xml/network_security_config.xml
new file mode 100644
index 0000000..dca93c0
--- /dev/null
+++ b/app/src/main/res/xml/network_security_config.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/test/java/com/example/webapplicationwithspring/ExampleUnitTest.java b/app/src/test/java/com/example/webapplicationwithspring/ExampleUnitTest.java
index 8535be7..3e67d74 100644
--- a/app/src/test/java/com/example/webapplicationwithspring/ExampleUnitTest.java
+++ b/app/src/test/java/com/example/webapplicationwithspring/ExampleUnitTest.java
@@ -2,7 +2,7 @@
import org.junit.Test;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
/**
* Example local unit test, which will execute on the development machine (host).
diff --git a/build.gradle b/build.gradle
index a5bb815..6c1ab27 100644
--- a/build.gradle
+++ b/build.gradle
@@ -7,7 +7,7 @@ buildscript {
}
dependencies {
- classpath 'com.android.tools.build:gradle:3.5.3'
+ classpath 'com.android.tools.build:gradle:4.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 452fe24..92ed0fc 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Tue Oct 06 22:28:10 MSK 2020
+#Sat Nov 07 17:43:14 MSK 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip