Ver Fonte

Merge branch 'V4_OSM' into V4

Iñigo Valentin há 9 anos atrás
pai
commit
ba0be10941

+ 324 - 373
app/src/main/java/com/ivalentin/margolariak/ActivityFutureLayout.java

@@ -2,19 +2,22 @@ package com.ivalentin.margolariak;
 
 import android.annotation.SuppressLint;
 import android.app.Dialog;
+import android.app.Fragment;
 import android.content.DialogInterface;
 import android.content.pm.PackageManager;
+import android.content.Intent;
 import android.database.Cursor;
 import android.database.sqlite.SQLiteDatabase;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
+import android.graphics.drawable.Drawable;
 import android.os.Build;
 import android.os.Bundle;
-import android.app.Fragment;
 import android.util.Log;
 import android.view.Gravity;
 import android.view.LayoutInflater;
 import android.view.View;
+import android.view.View.OnClickListener;
 import android.view.ViewGroup;
 import android.view.Window;
 import android.view.WindowManager;
@@ -23,6 +26,8 @@ import android.widget.Button;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.TextView;
+import android.preference.PreferenceManager;
+import android.net.Uri;
 
 import java.io.File;
 import java.text.ParseException;
@@ -30,6 +35,16 @@ import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.Locale;
+import java.util.ArrayList;
+
+import org.osmdroid.api.IMapController;
+import org.osmdroid.config.Configuration;
+
+import org.osmdroid.util.GeoPoint;
+import org.osmdroid.views.MapView;
+import org.osmdroid.views.overlay.ItemizedIconOverlay;
+import org.osmdroid.views.overlay.OverlayItem;
+import org.osmdroid.views.overlay.Polyline;
 
 /**
  * Fragment to display upcoming activities.
@@ -43,55 +58,50 @@ import java.util.Locale;
  */
 public class ActivityFutureLayout extends Fragment {
 
-	//Map stuff for the dialog
-	//private MapView mapView;
-	//private GoogleMap map;
-	//private LatLng location;
-	private String markerName = "";
 	private final Bundle bund = null;
 	private View v;
 
 	@SuppressWarnings("ResultOfMethodCallIgnored")
-    @SuppressLint("InflateParams")
-    @Override
-    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
-
-        //Load the layout
-        View view = inflater.inflate(R.layout.fragment_layout_activity_future, null);
-
-        //Get bundled id
-        Bundle bundle = this.getArguments();
-        int id = bundle.getInt("activity", -1);
-        if (id == -1){
-            Log.e("Activity error", "No such activity: " + id);
-            this.getActivity().onBackPressed();
-        }
-
-        //Get data from database
-        SQLiteDatabase db = SQLiteDatabase.openDatabase(getActivity().getDatabasePath(GM.DB.NAME).getAbsolutePath(), null, SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READONLY);
-        final Cursor cursor;
+	@SuppressLint("InflateParams")
+	@Override
+	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+
+		//Load the layout
+		View view = inflater.inflate(R.layout.fragment_layout_activity_future, null);
+
+		//Get bundled id
+		Bundle bundle = this.getArguments();
+		int id = bundle.getInt("activity", -1);
+		if (id == -1){
+			Log.e("Activity error", "No such activity: " + id);
+			this.getActivity().onBackPressed();
+		}
+
+		//Get data from database
+		SQLiteDatabase db = SQLiteDatabase.openDatabase(getActivity().getDatabasePath(GM.DB.NAME).getAbsolutePath(), null, SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READONLY);
+		final Cursor cursor;
 		String lang = GM.getLang();
 
-        cursor = db.rawQuery("SELECT id, title_" + lang+ " AS title, text_" + lang + " AS text, date, city, price, permalink FROM activity WHERE id = " + id + ";", null);
-        cursor.moveToFirst();
-
-        //Get display elements
-        ImageView images[] = new ImageView[5];
-        images[0] = (ImageView) view.findViewById(R.id.iv_activity_future_0);
-        images[1] = (ImageView) view.findViewById(R.id.iv_activity_future_1);
-        images[2] = (ImageView) view.findViewById(R.id.iv_activity_future_2);
-        images[3] = (ImageView) view.findViewById(R.id.iv_activity_future_3);
-        images[4] = (ImageView) view.findViewById(R.id.iv_activity_future_4);
-
-        TextView tvTitle = (TextView) view.findViewById(R.id.tv_activity_future_title);
-        TextView tvDate = (TextView) view.findViewById(R.id.tv_activity_future_date);
-        TextView tvCity = (TextView) view.findViewById(R.id.tv_activity_future_city);
-        TextView tvPrice = (TextView) view.findViewById(R.id.tv_activity_future_price);
-        WebView wvText = (WebView) view.findViewById(R.id.wv_activity_future_text);
-
-        //Set fields
-        tvTitle.setText(cursor.getString(1));
-        ((MainActivity) getActivity()).setSectionTitle(cursor.getString(1));
+		cursor = db.rawQuery("SELECT id, title_" + lang+ " AS title, text_" + lang + " AS text, date, city, price, permalink FROM activity WHERE id = " + id + ";", null);
+		cursor.moveToFirst();
+
+		//Get display elements
+		ImageView images[] = new ImageView[5];
+		images[0] = (ImageView) view.findViewById(R.id.iv_activity_future_0);
+		images[1] = (ImageView) view.findViewById(R.id.iv_activity_future_1);
+		images[2] = (ImageView) view.findViewById(R.id.iv_activity_future_2);
+		images[3] = (ImageView) view.findViewById(R.id.iv_activity_future_3);
+		images[4] = (ImageView) view.findViewById(R.id.iv_activity_future_4);
+
+		TextView tvTitle = (TextView) view.findViewById(R.id.tv_activity_future_title);
+		TextView tvDate = (TextView) view.findViewById(R.id.tv_activity_future_date);
+		TextView tvCity = (TextView) view.findViewById(R.id.tv_activity_future_city);
+		TextView tvPrice = (TextView) view.findViewById(R.id.tv_activity_future_price);
+		WebView wvText = (WebView) view.findViewById(R.id.wv_activity_future_text);
+
+		//Set fields
+		tvTitle.setText(cursor.getString(1));
+		((MainActivity) getActivity()).setSectionTitle(cursor.getString(1));
 		((MainActivity) getActivity()).setShareLink(String.format(getString(R.string.share_with_title), cursor.getString(1)), GM.SHARE.ACTIVITIES + cursor.getString(6));
 		if (Build.VERSION.SDK_INT >= 19) {
 			wvText.setLayerType(View.LAYER_TYPE_HARDWARE, null);
@@ -101,86 +111,86 @@ public class ActivityFutureLayout extends Fragment {
 		}
 		wvText.loadDataWithBaseURL(null, cursor.getString(2), "text/html", "utf-8", null);
 		//wvText.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
-        tvDate.setText(GM.formatDate(cursor.getString(3) + " 00:00:00", lang, true, false, false));
-        tvPrice.setText(String.format(getString(R.string.price), cursor.getInt(5)));
-        tvCity.setText(cursor.getString(4));
+		tvDate.setText(GM.formatDate(cursor.getString(3) + " 00:00:00", lang, true, false, false));
+		tvPrice.setText(String.format(getString(R.string.price), cursor.getInt(5)));
+		tvCity.setText(cursor.getString(4));
 
-        //Get images
-        Cursor imageCursor = db.rawQuery("SELECT image, idx FROM activity_image WHERE activity = " + id + " ORDER BY idx LIMIT 5;", null);
-        int i = 0;
+		//Get images
+		Cursor imageCursor = db.rawQuery("SELECT image, idx FROM activity_image WHERE activity = " + id + " ORDER BY idx LIMIT 5;", null);
+		int i = 0;
 		String image;
-        while (imageCursor.moveToNext()) {
-            image = imageCursor.getString(0);
-
-            //Check if image exists
-            File f;
-            f = new File(this.getActivity().getFilesDir().toString() + "/img/actividades/preview/" + image);
-            if (f.exists()){
-                //If the image exists, set it.
-                Bitmap myBitmap = BitmapFactory.decodeFile(this.getActivity().getFilesDir().toString() + "/img/actividades/preview/" + image);
-                images[i].setImageBitmap(myBitmap);
-            }
-            else {
-                //If not, create directories and download asynchronously
-                File fpath;
-                fpath = new File(this.getActivity().getFilesDir().toString() + "/img/actividades/preview/");
-                //noinspection ResultOfMethodCallIgnored
-                fpath.mkdirs();
-                new DownloadImage(GM.API.SERVER + "/img/actividades/preview/" + image, this.getActivity().getFilesDir().toString() + "/img/actividades/preview/" + image, images[i], GM.IMG.SIZE.PREVIEW).execute();
-            }
-            images[i].setVisibility(View.VISIBLE);
-            i ++;
-        }
-        imageCursor.close();
-        cursor.close();
-
-        //Get itinerary
-        Cursor cursorItinerary = db.rawQuery("SELECT activity_itinerary.id, activity_itinerary.name_" + lang + " AS name, description_" + lang + " AS description, start, place.name_" + lang + " AS placename, address_" + lang + " AS address, lat, lon FROM activity_itinerary, place WHERE activity_itinerary.place = place.id AND activity = " + id + ";", null);
-        if (cursorItinerary.getCount() <= 0){
-            LinearLayout sch = (LinearLayout) view.findViewById(R.id.ll_activity_future_schedule);
-            sch.setVisibility(View.GONE);
-        }
-        else{
-            LinearLayout list = (LinearLayout) view.findViewById(R.id.ll_activity_future_schedule_list);
-            LinearLayout entry;
-            LayoutInflater factory = LayoutInflater.from(getActivity());
-            while (cursorItinerary.moveToNext()) {
-                //Create a new row
-                entry = (LinearLayout) factory.inflate(R.layout.row_activity_schedule, null);
-
-                //Set time
-                TextView tvSchTime = (TextView) entry.findViewById(R.id.tv_row_activity_itinerary_time);
-                tvSchTime.setText(cursorItinerary.getString(3).substring(11, 16));
-
-                //Set title
-                TextView tvSchTitle = (TextView) entry.findViewById(R.id.tv_row_activity_itinerary_title);
-                tvSchTitle.setText(cursorItinerary.getString(1));
+		while (imageCursor.moveToNext()) {
+			image = imageCursor.getString(0);
+
+			//Check if image exists
+			File f;
+			f = new File(this.getActivity().getFilesDir().toString() + "/img/actividades/preview/" + image);
+			if (f.exists()){
+				//If the image exists, set it.
+				Bitmap myBitmap = BitmapFactory.decodeFile(this.getActivity().getFilesDir().toString() + "/img/actividades/preview/" + image);
+				images[i].setImageBitmap(myBitmap);
+			}
+			else {
+				//If not, create directories and download asynchronously
+				File fpath;
+				fpath = new File(this.getActivity().getFilesDir().toString() + "/img/actividades/preview/");
+				//noinspection ResultOfMethodCallIgnored
+				fpath.mkdirs();
+				new DownloadImage(GM.API.SERVER + "/img/actividades/preview/" + image, this.getActivity().getFilesDir().toString() + "/img/actividades/preview/" + image, images[i], GM.IMG.SIZE.PREVIEW).execute();
+			}
+			images[i].setVisibility(View.VISIBLE);
+			i ++;
+		}
+		imageCursor.close();
+		cursor.close();
+
+		//Get itinerary
+		Cursor cursorItinerary = db.rawQuery("SELECT activity_itinerary.id, activity_itinerary.name_" + lang + " AS name, description_" + lang + " AS description, start, place.name_" + lang + " AS placename, address_" + lang + " AS address, lat, lon FROM activity_itinerary, place WHERE activity_itinerary.place = place.id AND activity = " + id + ";", null);
+		if (cursorItinerary.getCount() <= 0){
+			LinearLayout sch = (LinearLayout) view.findViewById(R.id.ll_activity_future_schedule);
+			sch.setVisibility(View.GONE);
+		}
+		else{
+			LinearLayout list = (LinearLayout) view.findViewById(R.id.ll_activity_future_schedule_list);
+			LinearLayout entry;
+			LayoutInflater factory = LayoutInflater.from(getActivity());
+			while (cursorItinerary.moveToNext()) {
+				//Create a new row
+				entry = (LinearLayout) factory.inflate(R.layout.row_activity_schedule, null);
+
+				//Set time
+				TextView tvSchTime = (TextView) entry.findViewById(R.id.tv_row_activity_itinerary_time);
+				tvSchTime.setText(cursorItinerary.getString(3).substring(11, 16));
+
+				//Set title
+				TextView tvSchTitle = (TextView) entry.findViewById(R.id.tv_row_activity_itinerary_title);
+				tvSchTitle.setText(cursorItinerary.getString(1));
 
 				//Set Id
 				TextView tvSchId = (TextView) entry.findViewById(R.id.tv_row_activity_itinerary_id);
 				tvSchId.setText(cursorItinerary.getString(0));
 
-                //Set description
-                TextView tvSchDescription = (TextView) entry.findViewById(R.id.tv_row_activity_itinerary_description);
-                if (!cursorItinerary.getString(1).equals(cursorItinerary.getString(2))){
-                    tvSchDescription.setVisibility(View.GONE);
-                }
-                else {
-                    tvSchTitle.setText(cursorItinerary.getString(2));
-                }
-
-                //Set place
-                TextView tvSchPlace = (TextView) entry.findViewById(R.id.tv_row_activity_itinerary_place);
-                tvSchPlace.setText(cursorItinerary.getString(4));
-
-                //Set address
-                TextView tvSchAddress = (TextView) entry.findViewById(R.id.tv_row_activity_itinerary_address);
-                if (!cursorItinerary.getString(4).equals(cursorItinerary.getString(5))){
-                    tvSchAddress.setVisibility(View.GONE);
-                }
-                else {
-                    tvSchAddress.setText(cursorItinerary.getString(5));
-                }
+				//Set description
+				TextView tvSchDescription = (TextView) entry.findViewById(R.id.tv_row_activity_itinerary_description);
+				if (!cursorItinerary.getString(1).equals(cursorItinerary.getString(2))){
+					tvSchDescription.setVisibility(View.GONE);
+				}
+				else {
+					tvSchTitle.setText(cursorItinerary.getString(2));
+				}
+
+				//Set place
+				TextView tvSchPlace = (TextView) entry.findViewById(R.id.tv_row_activity_itinerary_place);
+				tvSchPlace.setText(cursorItinerary.getString(4));
+
+				//Set address
+				TextView tvSchAddress = (TextView) entry.findViewById(R.id.tv_row_activity_itinerary_address);
+				if (!cursorItinerary.getString(4).equals(cursorItinerary.getString(5))){
+					tvSchAddress.setVisibility(View.GONE);
+				}
+				else {
+					tvSchAddress.setText(cursorItinerary.getString(5));
+				}
 
 				//Set click listener
 				entry.setOnClickListener(new View.OnClickListener() {
@@ -192,283 +202,224 @@ public class ActivityFutureLayout extends Fragment {
 					}
 				});
 
-                list.addView(entry);
-            }
-        }
+				list.addView(entry);
+			}
+		}
 
 
-        cursorItinerary.close();
-        db.close();
+		cursorItinerary.close();
+		db.close();
 
 		v = view;
-        return view;
-    }
-
-    /**
-     * Shows a dialog with info about the selected event.
-     *
-     * @param id The event id
-     */
-    @SuppressWarnings("ConstantConditions")
-	private void showDialog(final int id){
-
-        //Create the dialog
-        final Dialog dialog = new Dialog(getActivity());
-
-        //Set up dialog window
-        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
-        dialog.setContentView(R.layout.dialog_schedule);
-
-        //Date formatters
-        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
-        SimpleDateFormat dayFormat = new SimpleDateFormat("yyyy-MM-dd-", Locale.US);
-        SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm", Locale.US);
-
-        //Set the custom dialog components - text, image and button
-        TextView tvTitle = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_title);
-        TextView tvDescription = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_description);
-        TextView tvHost = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_host);
-        TextView tvDate = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_date);
-        TextView tvTime = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_time);
-        TextView tvPlace = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_place);
-        TextView tvAddress = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_address);
-        Button btClose = (Button) dialog.findViewById(R.id.bt_schedule_close);
-
-        //Get info about the event
-        SQLiteDatabase db = SQLiteDatabase.openDatabase(getActivity().getDatabasePath(GM.DB.NAME).getAbsolutePath(), null, SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READONLY);
-        String lang = GM.getLang();
-        Cursor cursor = db.rawQuery("SELECT activity_itinerary.id, activity_itinerary.name_" + lang + ", description_" + lang + ", place, start, end, place.name_" + lang + ", address_" + lang + ", lat, lon FROM activity_itinerary, place WHERE place = place.id AND activity_itinerary.id = " + id + ";", null);
-        if (cursor.getCount() > 0){
-            cursor.moveToNext();
-
-            //Set title
-            tvTitle.setText(cursor.getString(1));
-            markerName = cursor.getString(1);
-
-            //Set description
-            tvDescription.setText(cursor.getString(2));
-
-            //Set host field hidden
-           	tvHost.setVisibility(View.GONE);
-
-            //Set date
-            try{
-                Date day = dateFormat.parse(cursor.getString(4));
-                Date date = new Date();
-                //If the event is today, show "Today" instead of the date
-                if (dayFormat.format(day).equals(dayFormat.format(date)))
-                    tvDate.setText(dialog.getContext().getString(R.string.today));
-
-                else{
-                    Calendar cal = Calendar.getInstance();
-                    cal.setTime(date);
-                    cal.add(Calendar.HOUR_OF_DAY, 24);
-
-                    //If the event is tomorrow, show "Tomorrow" instead of the date
-                    if (dayFormat.format(cal.getTime()).equals(dayFormat.format(date))){
-                        tvDate.setText(dialog.getContext().getString(R.string.tomorrow));
-                    }
-
-                    //Else, show the date
-                    else{
-                        SimpleDateFormat printFormat = new SimpleDateFormat("dd MMMM", Locale.US);
-                        tvDate.setText(printFormat.format(day));
-                    }
-                }
-            }
-            catch (Exception ex){
-                Log.e("Error parsing date", ex.toString());
-            }
-
-            //Set time
-            try{
-                if (cursor.getString(5) == null || cursor.getString(5).length() == 0) {
-                    tvTime.setText(timeFormat.format(dateFormat.parse(cursor.getString(4))));
-                }
-                else {
-                    String time = timeFormat.format(dateFormat.parse(cursor.getString(4))) + " - " + timeFormat.format(dateFormat.parse(cursor.getString(5)));
-                    tvTime.setText(time);
-                }
-            }
-            catch (ParseException ex){
-                Log.e("Error parsing time", ex.toString());
-            }
-
-            //Set the place
-            tvPlace.setText(cursor.getString(6));
-            tvAddress.setText(cursor.getString(7));
-
-            //Set up map
-            //location = new LatLng(Double.parseDouble(cursor.getString(8)), Double.parseDouble(cursor.getString(9)));
-            //mapView = (MapView) dialog.findViewById(R.id.mv_dialog_schedule_map);
-            //mapView.onCreate(bund);
-
-            //Close the db connection
-            cursor.close();
-            db.close();
-
-            //Set close button
-            btClose.setOnClickListener(new View.OnClickListener() {
-                @Override
-                public void onClick(View v) {
-                    dialog.dismiss();
-                }
-            });
-
-            //Actions to take when the dialog is cancelled
-            dialog.setOnCancelListener(new DialogInterface.OnCancelListener(){
-                @Override
-                public void onCancel(DialogInterface dialog) {
-                    /*if (map != null) {
-						if (!(ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
-							map.setMyLocationEnabled(false);
-						}
-					}
-                    if (mapView != null){
-                        mapView.onResume();
-                        mapView.onDestroy();
-                    }*/
-                }
-            });
-
-            //Show the dialog
-            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
-            lp.copyFrom(dialog.getWindow().getAttributes());
-            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
-            lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
-            lp.gravity = Gravity.CENTER;
-            lp.dimAmount = 0.0f;
-            dialog.getWindow().setAttributes(lp);
-
-            //Show dialog
-            dialog.show();
-
-            //Start the map
-            startMap();
-            //mapView.onResume();
-            dialog.setOnShowListener(new DialogInterface.OnShowListener(){
-
-                @Override
-                public void onShow(DialogInterface dialog) {
-                    // Gets to GoogleMap from the MapView and does initialization stuff
-                    startMap();
-
-                }
-            });
-
-        }
-    }
-
-	/**
-	 * Starts the map in the dialog.
-	 */
-	private void startMap(){
-		//mapView.getMapAsync(this);
+		return view;
 	}
 
 	/**
-	 * Called when the fragment is brought back into the foreground.
-	 * Resumes the map and the location manager.
+	 * Shows a dialog with info about the selected event.
 	 *
-	 * @see android.app.Fragment#onResume()
+	 * @param id The event id
 	 */
-	/*@Override
-	public void onResume() {
-		if (mapView != null)
-			mapView.onResume();
-		if (map != null) {
-			if (!(ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
-				map.setMyLocationEnabled(true);
+	@SuppressWarnings("ConstantConditions")
+	private void showDialog(final int id){
+
+		//Create the dialog
+		final Dialog dialog = new Dialog(getActivity());
+
+		//Set up dialog window
+		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
+		dialog.setContentView(R.layout.dialog_schedule);
+
+		//Date formatters
+		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
+		SimpleDateFormat dayFormat = new SimpleDateFormat("yyyy-MM-dd-", Locale.US);
+		SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm", Locale.US);
+
+		//Set the custom dialog components - text, image, buttons, map
+		LinearLayout llPlace = (LinearLayout) dialog.findViewById(R.id.ll_dialog_schedule_place);
+		TextView tvTitle = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_title);
+		TextView tvDescription = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_description);
+		TextView tvHost = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_host);
+		TextView tvDate = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_date);
+		TextView tvTime = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_time);
+		TextView tvPlace = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_place);
+		TextView tvAddress = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_address);
+		TextView tvOsm = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_osm);
+		Button btClose = (Button) dialog.findViewById(R.id.bt_schedule_close);
+		MapView mapView = (MapView) dialog.findViewById(R.id.mv_dialog_schedule_map);
+
+		// Basic map setup
+		mapView.setMultiTouchControls(true);
+		IMapController mapController = mapView.getController();
+
+		//Get info about the event
+		SQLiteDatabase db = SQLiteDatabase.openDatabase(getActivity().getDatabasePath(GM.DB.NAME).getAbsolutePath(), null, SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READONLY);
+		String lang = GM.getLang();
+		Cursor cursor = db.rawQuery("SELECT id, name_" + lang + ", description_" + lang + ", place, route, start, end, FROM activity_itinerary WHERE activity.id = " + id + " ORDER BY start;", null);
+		if (cursor.getCount() > 0){
+
+			cursor.moveToNext();
+
+			// Get data
+			String title = cursor.getString(1);
+			String description = "";
+			if (!cursor.isNull(2)){
+				description = cursor.getString(2);
+			}
+			int placeId = 0;
+			if (!cursor.isNull(3)){
+				placeId = cursor.getInt(3);
+			}
+			int routeId = 0;
+			if (!cursor.isNull(4)){
+				routeId = cursor.getInt(4);
+			}
+			String strStart = cursor.getString(5);
+			String strEnd = "";
+			if (!cursor.isNull(6)){
+				strEnd = cursor.getString(6);
 			}
-		}
-		super.onResume();
-	}*/
 
-	/**
-	 * Called when the fragment is destroyed.
-	 * Finishes the map.
-	 *
-	 * @see android.app.Fragment#onDestroy()
-	 */
-	/*@Override
-	public void onDestroy() {
-		super.onDestroy();
-		if (map != null) {
-			if (!(ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
-				map.setMyLocationEnabled(false);
+			//Set title
+			tvTitle.setText(title);
+
+			//Set description
+			tvDescription.setText(description);
+
+			//Hide the host and date fields
+		   	tvHost.setVisibility(View.GONE);
+			tvDate.setVisibility(View.GONE);
+
+			//Set time
+			try{
+				if (strEnd.length() == 0) {
+					tvTime.setText(timeFormat.format(dateFormat.parse(strStart)));
+				}
+				else {
+					String time = timeFormat.format(dateFormat.parse(strStart)) + " - " + timeFormat.format(dateFormat.parse(strEnd));
+					tvTime.setText(time);
+				}
+			}
+			catch (ParseException ex){
+				Log.e("Error parsing time", ex.toString());
 			}
-		}
-		if (mapView != null){
-			mapView.onResume();
-			mapView.onDestroy();
-		}
-	}*/
 
-	/**
-	 * Called when the fragment is paused.
-	 * Finishes the map.
-	 *
-	 * @see android.app.Fragment#onPause()
-	 */
-	/*@Override
-	public void onPause() {
-		super.onDestroy();
-		if (map != null) {
-			if (!(ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
-				map.setMyLocationEnabled(false);
+			//Set the place
+			if (routeId != 0){
+				llPlace.setVisibility(View.GONE);
+				Cursor routeCursor = db.rawQuery("SELECT id, c_lat, c_lon, zoom FROM route WHERE id = " + routeId + ";", null);
+				if (routeCursor.moveToNext()) {
+
+					// Configure map route
+					mapController.setZoom(routeCursor.getInt(3));
+					GeoPoint center = new GeoPoint(routeCursor.getDouble(1), routeCursor.getDouble(2));
+					mapController.setCenter(center);
+
+					// Read from route_point and draw the route on the map.
+					Cursor pointCursor = db.rawQuery("SELECT lat_o, lon_o, lat_d, lon_d FROM route_point WHERE route = " + routeId + " ORDER BY part;", null);
+					final ArrayList<GeoPoint> points = new ArrayList<GeoPoint>();
+					GeoPoint lastPoint = new GeoPoint(0.0, 0.0);
+					while (pointCursor.moveToNext()){
+
+						points.add(new GeoPoint(pointCursor.getDouble(0), pointCursor.getDouble(1)));
+						lastPoint = new GeoPoint(pointCursor.getDouble(2), pointCursor.getDouble(3));
+					}
+					// For the last one, also take destination
+					points.add(lastPoint);
+
+					pointCursor.close();
+
+					//Create path
+					Polyline line = new Polyline();
+					line.setPoints(points);
+					line.setColor(getResources().getColor(R.color.background_menu));
+					mapView.getOverlays().add(line);
+
+				}
+
 			}
+			else{
+				Cursor placeCursor = db.rawQuery("SELECT name_" + lang + ", address_" + lang + ", lat, lon FROM place WHERE id = " + placeId + ";", null);
+				if (placeCursor.moveToNext()){
+					tvPlace.setText(placeCursor.getString(0));
+					tvAddress.setText(placeCursor.getString(1));
+
+					// Configure map marker
+					mapController.setZoom(17);
+					GeoPoint center = new GeoPoint(placeCursor.getDouble(2), placeCursor.getDouble(3));
+					mapController.setCenter(center);
+					OverlayItem locationOverlayItem = new OverlayItem(title, placeCursor.getString(0), center);
+					Drawable locationMarker = this.getResources().getDrawable(R.drawable.pinpoint);
+					locationOverlayItem.setMarker(locationMarker);
+					final ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
+					items.add(locationOverlayItem);
+					ItemizedIconOverlay locationOverlay = new ItemizedIconOverlay<OverlayItem>(items,
+							new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
+								public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
+									return true;
+								}
+								public boolean onItemLongPress(final int index, final OverlayItem item) {
+									return true;
+								}
+							}, getContext());
+					mapView.getOverlays().add(locationOverlay);
+				}
+				placeCursor.close();
+			}
+
+			//Set up OpenStreetMap attribution
+			tvOsm.setOnClickListener(new OnClickListener() {
+				@Override
+				public void onClick(View view) {
+					Intent i = new Intent(Intent.ACTION_VIEW);
+					i.setData(Uri.parse(GM.URL.OSM_COPYRIGHT));
+					startActivity(i);
+				}
+			});
+
+			//Close the db connection
+			cursor.close();
+			db.close();
+
+			//Set close button
+			btClose.setOnClickListener(new View.OnClickListener() {
+				@Override
+				public void onClick(View v) {
+					dialog.dismiss();
+				}
+			});
+
+			//Show the dialog
+			WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
+			lp.copyFrom(dialog.getWindow().getAttributes());
+			lp.width = WindowManager.LayoutParams.MATCH_PARENT;
+			lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
+			lp.gravity = Gravity.CENTER;
+			lp.dimAmount = 0.0f;
+			dialog.getWindow().setAttributes(lp);
+
+			//Show dialog
+			dialog.show();
+
 		}
-		if (mapView != null){
-			mapView.onPause();
-		}
-	}*/
+	}
 
 	/**
-	 * Called in a situation of low memory.
+	 * Called when the activity is resumed.
 	 * Lets the map handle this situation.
 	 *
-	 * @see android.app.Fragment#onLowMemory()
+	 * @see android.app.Fragment#onResume()
 	 */
-	/*@Override
-	public void onLowMemory() {
-		super.onLowMemory();
-		if (mapView != null){
-			if (!(ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
-				mapView.onResume();
-			}
-			mapView.onLowMemory();
-		}
-	}*/
+	@Override
+	public void onResume() {
+		Configuration.getInstance().load(getContext(), PreferenceManager.getDefaultSharedPreferences(getContext()));
+		super.onResume();
+	}
 
 	/**
-	 * Called when the map is ready to be displayed.
-	 * Sets the map options and a marker for the map.
-	 *
-	 * @param googleMap The map to be shown
-	 *
-	 * @see com.google.android.gms.maps.OnMapReadyCallback#onMapReady(com.google.android.gms.maps.GoogleMap)
+	 * Checks app permission to access the user location.
+	 * @return true if the permission has been granted, false otherwise.
 	 */
-	/*@Override
-	public void onMapReady(GoogleMap googleMap) {
-		this.map = googleMap;
-
-		map.getUiSettings().setMyLocationButtonEnabled(false);
-		if (!(ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
-			map.setMyLocationEnabled(true);
-		}
-		// Needs to call MapsInitializer before doing any CameraUpdateFactory calls
-		try {
-			MapsInitializer.initialize(this.getActivity());
-			CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(location, 14);
-			map.animateCamera(cameraUpdate);
-		} catch (Exception e) {
-			Log.e("Error initializing maps", e.toString());
-		}
-		//Set GM marker
-		MarkerOptions mo = new MarkerOptions();
-		mo.title(markerName);
-		mo.position(location);
-		map.addMarker(mo);
-
-	}*/
+	private boolean checkLocationPermission(){
+		return getContext().checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && getContext().checkSelfPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED;
+	}
 }

+ 97 - 136
app/src/main/java/com/ivalentin/margolariak/LocationLayout.java

@@ -1,13 +1,13 @@
 package com.ivalentin.margolariak;
 
 import java.util.Locale;
+import java.util.ArrayList;
 
 import android.app.Activity;
 import android.content.Context;
 import android.content.pm.PackageManager;
 import android.database.Cursor;
 import android.database.sqlite.SQLiteDatabase;
-import android.location.Criteria;
 import android.location.Location;
 import android.location.LocationListener;
 import android.location.LocationManager;
@@ -19,11 +19,17 @@ import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.TextView;
+import android.graphics.drawable.Drawable;
+
+import org.osmdroid.api.IMapController;
+
+import org.osmdroid.util.GeoPoint;
+import org.osmdroid.views.MapView;
+import org.osmdroid.views.overlay.ItemizedIconOverlay;
+import org.osmdroid.views.overlay.OverlayItem;
 
 /**
  * Section that shows a map with the location of Gasteizko Margolariak.
- * If no recent report location, it will explain that and will show the
- * next scheduled activity.
  *
  * @author Iñigo Valentin
  *
@@ -32,42 +38,45 @@ import android.widget.TextView;
  */
 public class LocationLayout extends Fragment implements LocationListener {
 
-	//The map view
-	//private MapView mapView;
-	//GoogleMap gMap;
+	//The map view stuff
+	private MapView mapView;
+	private Drawable locationMarker;
 
+	// The location manager
 	private LocationManager locationManager;
 
 	//Locations for the user and Gasteizko Margolariak
-	//private LatLng gmLocation;
+	private GeoPoint gmLocation;
 
 	//The main View
 	private View v;
 
-	private double lat, lon;
-
-	//Map marker
-	//Marker gmMarker;
-	//MarkerOptions moGm = new MarkerOptions();
-
+	// Handler to refresh the location.
 	private final Handler markerHandler = new Handler();
-
 	private final Runnable resetMarker = new Runnable() {
 		@Override
 		public void run() {
 
-			/*if (gmMarker != null) {
-				gmMarker.remove();
+			if (mapView != null) {
 				if (refreshLocation()) {
-					gmMarker.setPosition(new LatLng(lat, lon));
-					gmLocation = new LatLng(lat, lon);
-					//moGm = new MarkerOptions();
-					moGm.title(v.getContext().getString(R.string.app_name));
-					moGm.position(gmLocation);
-					moGm.icon(BitmapDescriptorFactory.fromResource(R.drawable.pinpoint_gm));
-					gmMarker = gMap.addMarker(moGm);
+					
+					//mapController.setCenter(self.gmLocation);
+					OverlayItem locationOverlayItem = new OverlayItem("Gasteizko Margolariak", "", gmLocation);
+					locationOverlayItem.setMarker(locationMarker);
+					final ArrayList<OverlayItem> items = new ArrayList<>();
+					items.add(locationOverlayItem);
+					ItemizedIconOverlay locationOverlay = new ItemizedIconOverlay<>(items,
+							new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
+								public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
+									return true;
+								}
+								public boolean onItemLongPress(final int index, final OverlayItem item) {
+									return true;
+								}
+							}, getContext());
+					mapView.getOverlays().add(locationOverlay);
 				}
-			}*/
+			}
 			markerHandler.postDelayed(resetMarker, GM.LOCATION.INTERVAL);
 		}
 	};
@@ -91,6 +100,7 @@ public class LocationLayout extends Fragment implements LocationListener {
 		//Set up
 		locationManager = (LocationManager) v.getContext().getSystemService(Context.LOCATION_SERVICE);
 		if (checkLocationPermission()){
+			locationManager.requestSingleUpdate(LocationManager.GPS_PROVIDER, this, null);
 			locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, GM.LOCATION.ACCURACY.TIME, GM.LOCATION.ACCURACY.SPACE, this);
 		}
 
@@ -101,90 +111,72 @@ public class LocationLayout extends Fragment implements LocationListener {
 		refreshLocation();
 
 		//Periodically check map
-		//markerHandler.post(resetMarker);
-
-		//mapView = (MapView) v.findViewById(R.id.mapview);
-		//mapView.onCreate(savedInstanceState);
+		markerHandler.post(resetMarker);
 
-		// Gets to GoogleMap from the MapView and does initialization stuff
-		//mapView.getMapAsync(this);
+		// Set up the map
+		this.mapView = (MapView) v.findViewById(R.id.mapview);
+		this.mapView.setMultiTouchControls(true);
+		IMapController mapController = mapView.getController();
+		mapController.setZoom(17);
+		mapController.setCenter(gmLocation);
+		this.locationMarker = this.getResources().getDrawable(R.drawable.pinpoint, null);
 
 		//Return the view
 		return v;
 	}
 
+
 	/**
 	 * Called when the fragment is bought back to the foreground. 
 	 * Ensures that the map is displayed then, and activates the location manager.
 	 *
 	 * @see android.app.Fragment#onResume()
 	 */
-	/*@Override
+	@Override
 	public void onResume() {
-		if (mapView != null) {
-			mapView.onResume();
-		}
-		if (!(ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)){
+		if (checkLocationPermission()){
 			locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, GM.LOCATION.ACCURACY.TIME, GM.LOCATION.ACCURACY.SPACE, this);
 		}
 		super.onResume();
-
 		markerHandler.post(resetMarker);
-	}*/
+	}
+
 
 	/**
 	 * Called when the fragment is paused.
 	 * Stops the location manager
 	 * @see android.app.Fragment#onPause()
 	 */
-	/*@Override
+	@Override
 	public void onPause(){
-		if (!(ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
+		if (checkLocationPermission()) {
 			locationManager.removeUpdates(this);
 		}
 		super.onPause();
 
 		markerHandler.removeCallbacks(resetMarker);
-	}*/
+	}
+
 
 	/**
 	 * Called when the fragment is destroyed. 
 	 * Ensures that the map is destroyed then.
 	 * 
-	 * @see android.support.v4.app.Fragment#onDestroy()
+	 * @see Fragment#onDestroy()
 	 */
-	/*@Override
+	@Override
 	public void onDestroy() {
 		super.onDestroy();
-		if (!(ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
+		if (checkLocationPermission()) {
 			locationManager.removeUpdates(this);
 		}
 
-		if (mapView != null){
-			mapView.onResume();
-			mapView.onDestroy();
-		}
-
 		markerHandler.removeCallbacks(resetMarker);
-	}*/
+	}
 
-	/**
-	 * Called in a situation of low memory. 
-	 * It let's the mapView handle the situation.
-	 * 
-	 * @see android.support.v4.app.Fragment#onLowMemory()
-	 */
-	/*@Override
-	public void onLowMemory() {
-		super.onLowMemory();
-		if (mapView != null){
-			mapView.onResume();
-			mapView.onLowMemory();
-		}
-	}*/
 
 	/**
-	 * Refresh the global variables "lat" and "lon".
+	 * Refresh the location of Gasteizko Margolariak, by updating the class attribute gmLocation.
 	 *
 	 * Uses the most recent data in the database, if they are not older than 10 minutes.
 	 *
@@ -202,75 +194,42 @@ public class LocationLayout extends Fragment implements LocationListener {
 		}
 		else {
 			cursor.moveToFirst();
-			lat = cursor.getDouble(0);
-			lon = cursor.getDouble(1);
+			gmLocation = new GeoPoint(cursor.getDouble(0), cursor.getDouble(1));
 			cursor.close();
 			db.close();
 			return true;
 		}
-
 	}
 
+
 	/**
-	 * Called when the map is ready to be used. 
-	 * Initializes it and sets the Gasteizko Margolariak marker.
-	 * 
+	 * Recalculates the distance between the user and Gasteizko Margolariak.
+	 * Prints the distance to a TextView.
 	 *
+	 * @param userLocation The new user location.
+	 *
+	 * @see android.location.LocationListener#onLocationChanged(android.location.Location)
 	 */
-	/*@Override
-	public void onMapReady(GoogleMap googleMap) {
-
-		gMap = googleMap;
-
-		if (!(ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
-			googleMap.setMyLocationEnabled(true);
-		}
-		
-		googleMap.getUiSettings().setMyLocationButtonEnabled(false);
-		// Needs to call MapsInitializer before doing any CameraUpdateFactory calls
-		try {
-			MapsInitializer.initialize(this.getActivity());
-		} catch (Exception e) {
-			Log.e("Error initializing maps", e.toString());
-		}
-
-		//If there is a location, set it
-		if (refreshLocation()) {
-
-			//Set the marker
-			gmLocation = new LatLng(lat, lon);
-			moGm.title(v.getContext().getString(R.string.app_name));
-			moGm.position(gmLocation);
-			moGm.icon(BitmapDescriptorFactory.fromResource(R.drawable.pinpoint_gm));
-			gmMarker = googleMap.addMarker(moGm);
-			googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lon), 14.0f));
-		}
-
-		//Start device location requests
-		if (!(ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
-			locationManager.requestLocationUpdates(locationManager.getBestProvider(new Criteria(), true), GM.LOCATION.ACCURACY.TIME, GM.LOCATION.ACCURACY.SPACE, this);
-			onLocationChanged(locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER));
-		}
-	}*/
-
-
-	private void calCulateDistance(Location userLocation){
+	private void calculateDistance(Location userLocation){
 		TextView text = (TextView) v.findViewById(R.id.tv_location_distance);
-		try {
-			Double distance = Distance.calculateDistance(userLocation.getLatitude(), userLocation.getLongitude(), lat, lon);
-			if (distance <= 2) {
-				distance = 1000 * distance;
-				text.setText(String.format(getString(R.string.home_section_location_text_short), distance.intValue(), (int) (0.012 * distance.intValue())));
-			} else {
-				text.setText(String.format(getString(R.string.home_section_location_text_long), String.format(Locale.US, "%.02f", distance)));
+		if (userLocation != null){
+			try {
+				Double distance = Distance.calculateDistance(userLocation.getLatitude(), userLocation.getLongitude(), gmLocation.getLatitude(), gmLocation.getLongitude());
+				if (distance <= 2) {
+					distance = 1000 * distance;
+					text.setText(String.format(getString(R.string.home_section_location_text_short), distance.intValue(), (int) (0.012 * distance.intValue())));
+				} else {
+					text.setText(String.format(getString(R.string.home_section_location_text_long), String.format(Locale.US, "%.02f", distance)));
+				}
+			}
+			catch(Exception ex){
+				Log.e("LOCATION_LAYOUT", "Distance error: " + ex.toString());
+				text.setText("");
 			}
-		}
-		catch(Exception ex){
-			Log.e("Distance error", ex.toString());
-			text.setText("");
 		}
 	}
 
+
 	/**
 	 * Called when the user location changes.
 	 * Recalculates the list of around events and calls updateLocation() to
@@ -282,11 +241,24 @@ public class LocationLayout extends Fragment implements LocationListener {
 	 */
 	@Override
 	public void onLocationChanged(Location location) {
-		calCulateDistance(location);
+		calculateDistance(location);
 	}
 
+
+	/**
+	 * Checks app permission to access the user location.
+	 * @return true if the permission has been granted, false otherwise.
+	 *
+	 * @see android.app.Fragment#onResume()
+	 */
+	private boolean checkLocationPermission(){
+		return getContext().checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && getContext().checkSelfPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED;
+	}
+
+
 	/**
 	 * Called when the location provider changes it's state.
+	 * Does nothing.
 	 *
 	 * @param provider The name of the provider
 	 * @param status Status code of the provider
@@ -295,27 +267,26 @@ public class LocationLayout extends Fragment implements LocationListener {
 	 * @see android.location.LocationListener#onStatusChanged(java.lang.String, int, android.os.Bundle)
 	 */
 	@Override
-	public void onStatusChanged(String provider, int status, Bundle extras) {
-		//populateAround();
+		public void onStatusChanged(String provider, int status, Bundle extras) {
 	}
 
 
 	/**
 	 * Called when a location provider is enabled.
-	 * Recalculates the list of events.
+	 * Does nothing.
 	 *
 	 * @param provider The name of the provider
 	 *
 	 * @see android.location.LocationListener#onProviderEnabled(java.lang.String)
 	 */
 	@Override
-	public void onProviderEnabled(String provider) {
-		//populateAround();
+		public void onProviderEnabled(String provider) {
 	}
 
+
 	/**
 	 * Called when a location provider is disabled.
-	 * Recalculates the list of events.
+	 * Does nothing.
 	 *
 	 * @param provider The name of the provider
 	 *
@@ -323,15 +294,5 @@ public class LocationLayout extends Fragment implements LocationListener {
 	 */
 	@Override
 	public void onProviderDisabled(String provider) {
-		//populateAround();
 	}
-
-	/**
-	 * Checks app permission to access the user location.
-	 * @return true if the permission has been granted, false otherwise.
-	 *
-	 * @see android.app.Fragment#onResume()
-	 */
-	private boolean checkLocationPermission(){
-		return getContext().checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && getContext().checkSelfPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED;	}
 }

+ 8 - 16
app/src/main/java/com/ivalentin/margolariak/ScheduleLayout.java

@@ -63,12 +63,8 @@ public class ScheduleLayout extends Fragment{
 	private final String dates[] = new String[40];
 	private int dateCount = 0;
 	private int selected = 0;
-
-	//Map stuff for the dialog
-	private MapView mapView;
-	private int route;
+	
 	private View view;
-	private String markerName = "";
 
 	/**
 	 * Run when the fragment is inflated.
@@ -87,17 +83,12 @@ public class ScheduleLayout extends Fragment{
 		Calendar calendar = Calendar.getInstance();
 		String year = Integer.toString(calendar.get(Calendar.YEAR));
 
-
-		//Set bundle for the map
-		bund = savedInstanceState;
-
 		//Load the layout
 		view = inflater.inflate(R.layout.fragment_layout_schedule, null);
 		view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
 			@Override
 			public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
 				CustomScrollView sv = (CustomScrollView) v.findViewById(R.id.sv_schedule);
-				Log.d("SV", "INVALIDATED");
 				sv.invalidate();
 			}
 		});
@@ -407,6 +398,11 @@ public class ScheduleLayout extends Fragment{
 		TextView tvAddress = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_address);
 		Button btClose = (Button) dialog.findViewById(R.id.bt_schedule_close);
 		TextView tvOsm = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_osm);
+		MapView mapView = (MapView) dialog.findViewById(R.id.mv_dialog_schedule_map);
+		
+		// Basic map configuration
+		mapView.setMultiTouchControls(true);
+		IMapController mapController = mapView.getController();
 
 		//Get info about the event
 		SQLiteDatabase db = SQLiteDatabase.openDatabase(getActivity().getDatabasePath(GM.DB.NAME).getAbsolutePath(), null, SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READONLY);
@@ -546,11 +542,7 @@ public class ScheduleLayout extends Fragment{
 				Log.e("Error parsing time", ex.toString());
 			}
 
-			//Set up map
 
-			mapView = (MapView) dialog.findViewById(R.id.mv_dialog_schedule_map);
-			mapView.setMultiTouchControls(true);
-			IMapController mapController = mapView.getController();
 
 
 			//Set the place
@@ -582,7 +574,7 @@ public class ScheduleLayout extends Fragment{
 					Polyline line = new Polyline();
 					line.setPoints(points);
 					line.setColor(getResources().getColor(R.color.background_menu));
-					this.mapView.getOverlays().add(line);
+					mapView.getOverlays().add(line);
 
 				}
 
@@ -611,7 +603,7 @@ public class ScheduleLayout extends Fragment{
 									return true;
 								}
 							}, getContext());
-					this.mapView.getOverlays().add(locationOverlay);
+					mapView.getOverlays().add(locationOverlay);
 				}
 				placeCursor.close();
 			}

+ 13 - 6
app/src/main/res/layout/fragment_layout_location.xml

@@ -54,12 +54,19 @@
 				android:text="@string/home_section_location_text_calculating"
 				android:textAppearance="?android:attr/textAppearanceSmall"/>
 
-			<com.google.android.gms.maps.MapView
-				android:id="@+id/mapview"
-				android:layout_width="fill_parent"
-				android:layout_height="fill_parent"
-				android:layout_margin="7dp"
-				android:minHeight="150dp"/>
+			<LinearLayout
+				android:layout_width="match_parent"
+				android:layout_height="match_parent"
+				android:layout_weight=".95"
+				android:background="@drawable/map"
+				android:padding="3dp">
+
+				<org.osmdroid.views.MapView
+					android:id="@+id/mapview"
+					android:layout_width="match_parent"
+					android:layout_height="match_parent"/>
+
+			</LinearLayout>
 		</LinearLayout>
 
 	</LinearLayout>