Эх сурвалжийг харах

Schedule map centered forroutes. Link to Open Street Maps copyright.

Iñigo Valentin 9 жил өмнө
parent
commit
3f068d2b2a

+ 6 - 1
app/src/main/java/com/ivalentin/margolariak/GM.java

@@ -328,7 +328,7 @@ final class GM {
 				/**
 				 * Creates the table "route" on the database.
 				 */
-				static final String ROUTE = "CREATE TABLE IF NOT EXISTS route (id INT, name VARCHAR, mins INT);";
+				static final String ROUTE = "CREATE TABLE IF NOT EXISTS route (id INT, name VARCHAR, mins INT, c_lat DOUBLE, c_lon DOUBLE, zoom INT);";
 
 				/**
 				 * Creates the table "route_point" on the database.
@@ -920,6 +920,11 @@ final class GM {
 		 */
 		static final String GITHUB = "https://github.com/GasteizkoMargolariak/GasteizkoMargolariakApp";
 
+		/**
+		 * URL of the Open Street Maps copyright.
+		 */
+		static final String OSM_COPYRIGHT = "https://www.openstreetmap.org/copyright";
+
 		/**
 		 * URL of the server.
 		 */

+ 139 - 48
app/src/main/java/com/ivalentin/margolariak/ScheduleLayout.java

@@ -13,10 +13,12 @@ import android.app.Dialog;
 import android.content.DialogInterface;
 import android.content.DialogInterface.OnCancelListener;
 import android.content.DialogInterface.OnShowListener;
+import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.database.Cursor;
 import android.database.sqlite.SQLiteDatabase;
 import android.graphics.drawable.Drawable;
+import android.net.Uri;
 import android.os.Bundle;
 import android.app.Fragment;
 import android.preference.PreferenceManager;
@@ -395,70 +397,114 @@ public class ScheduleLayout extends Fragment{
 		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 tvSponsor = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_sponsor);
 		TextView tvDate = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_date);
 		TextView tvTime = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_time);
+		LinearLayout llPlace = (LinearLayout) dialog.findViewById(R.id.ll_dialog_schedule_place);
 		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);
+		TextView tvOsm = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_osm);
 
 		//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;
 		if (schedule == GM.SCHEDULE.MARGOLARIAK){
-			cursor = db.rawQuery("SELECT festival_event_gm.id, title_" + lang + ", description_" + lang + ", place, route, start, end, name_" + lang + ", address_" + lang + ", lat, lon, host, sponsor FROM festival_event_gm, place WHERE place = place.id AND festival_event_gm.id = " + id + ";", null);
+			//cursor = db.rawQuery("SELECT festival_event_gm.id, title_" + lang + ", description_" + lang + ", place, route, start, end, name_" + lang + ", address_" + lang + ", lat, lon, host, sponsor FROM festival_event_gm, place WHERE place = place.id AND festival_event_gm.id = " + id + ";", null);
+			cursor = db.rawQuery("SELECT id, title_" + lang + ", description_" + lang + ", place, route, start, end, host, sponsor FROM festival_event_gm WHERE id = " + id + ";", null);
 		}
 		else{
-			cursor = db.rawQuery("SELECT festival_event_city.id, title_" + lang + ", description_" + lang + ", place, route, start, end, name_" + lang + ", address_" + lang + ", lat, lon, host, sponsor FROM, sponsor festival_event_city, place WHERE place = place.id AND festival_event_city.id = " + id + ";", null);
+			//cursor = db.rawQuery("SELECT festival_event_city.id, title_" + lang + ", description_" + lang + ", place, route, start, end, name_" + lang + ", address_" + lang + ", lat, lon, host, sponsor FROM, sponsor festival_event_city, place WHERE place = place.id AND festival_event_city.id = " + id + ";", null);
+			cursor = db.rawQuery("SELECT id, title_" + lang + ", description_" + lang + ", place, route, start, end, host, sponsor FROM festival_event_city WHERE id = " + id + ";", null);
 		}
 		if (cursor.getCount() > 0){
 			cursor.moveToNext();
 
+			String title = cursor.getString(1);
+			String description = "";
+			if (!cursor.isNull(2)){
+				description = cursor.getString(2);
+			}
+			String strStart = cursor.getString(5);
+			String strEnd = "";
+			if (!cursor.isNull(6)){
+				strEnd = cursor.getString(6);
+			}
+			int placeId = 0;
+			if (!cursor.isNull(3)){
+				placeId = cursor.getInt(3);
+			}
+			int routeId = 0;
+			if (!cursor.isNull(4)){
+				routeId = cursor.getInt(4);
+			}
+			int hostId = 0;
+			if (!cursor.isNull(7)){
+				hostId = cursor.getInt(7);
+			}
+			int sponsorId = 0;
+			if (!cursor.isNull(8)){
+				sponsorId = cursor.getInt(8);
+			}
+
 			//Set title
-			tvTitle.setText(cursor.getString(1));
-			markerName = cursor.getString(1);
+			tvTitle.setText(title);
 
 			//Set description
-			if (cursor.getString(2) != null && cursor.getString(2).length() > 0) {
-				tvDescription.setText(cursor.getString(2));
+			if (description.length() > 0) {
+				tvDescription.setText(description);
 			}
 			else{
 				tvDescription.setVisibility(View.GONE);
 			}
 
 			//Set host
-			if (cursor.getString(10) != null){
-				Cursor hostCursor = db.rawQuery("SELECT name_" + lang + " FROM people WHERE id = " + cursor.getString(10) + ";", null);
+			if (hostId != 0){
+				Cursor hostCursor = db.rawQuery("SELECT name_" + lang + " FROM people WHERE id = " + hostId + ";", null);
 				if (hostCursor.moveToNext()){
 					tvHost.setVisibility(View.VISIBLE);
 					tvHost.setText(String.format(getString(R.string.schedule_host), hostCursor.getString(0)));
 				}
 				hostCursor.close();
-				// TODO. Add sponsor.
 			}
 			else{
 				tvHost.setVisibility(View.GONE);
 			}
 
+			//Set sponsor
+			if (sponsorId != 0){
+				Cursor sponsorCursor = db.rawQuery("SELECT name_" + lang + " FROM people WHERE id = " + sponsorId + ";", null);
+				if (sponsorCursor.moveToNext()){
+					tvSponsor.setVisibility(View.VISIBLE);
+					tvSponsor.setText(String.format(getString(R.string.schedule_sponsor), sponsorCursor.getString(0)));
+				}
+				sponsorCursor.close();
+			}
+			else{
+					tvSponsor.setVisibility(View.GONE);
+			}
+
+
 			//Set date
 			try{
-				Date day = dateFormat.parse(cursor.getString(4));
+				Date day = dateFormat.parse(strStart);
 				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);
+					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));
-				    }
+					//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{
+					//Else, show the date
+					else{
 						SimpleDateFormat printFormat;
 						switch (lang){
 							case "en":
@@ -486,11 +532,11 @@ public class ScheduleLayout extends Fragment{
 
 			//Set time
 			try{
-				if (cursor.getString(6) == null || cursor.getString(6).length() == 0) {
-					tvTime.setText(timeFormat.format(dateFormat.parse(cursor.getString(5))));
+				if (strEnd.length() == 0) {
+					tvTime.setText(timeFormat.format(dateFormat.parse(strStart)));
 				}
 				else {
-					String time = timeFormat.format(dateFormat.parse(cursor.getString(5))) + " - " + timeFormat.format(dateFormat.parse(cursor.getString(6)));
+					String time = timeFormat.format(dateFormat.parse(strStart)) + " - " + timeFormat.format(dateFormat.parse(strEnd));
 					tvTime.setText(time);
 				}
 			}
@@ -498,38 +544,83 @@ public class ScheduleLayout extends Fragment{
 				Log.e("Error parsing time", ex.toString());
 			}
 
-			//Set the place
-			tvPlace.setText(cursor.getString(7));
-			tvAddress.setText(cursor.getString(8));
-
 			//Set up map
-			// TODO if route...
 
 			mapView = (MapView) dialog.findViewById(R.id.mv_dialog_schedule_map);
-
 			mapView.setMultiTouchControls(true);
 			IMapController mapController = mapView.getController();
-			mapController.setZoom(15);
-			GeoPoint center = new GeoPoint(cursor.getDouble(9), cursor.getDouble(10));
-			mapController.setCenter(center);
-
-			OverlayItem locationOverlayItem = new OverlayItem(cursor.getString(1), cursor.getString(7), center);
-			Drawable locationMarker = this.getResources().getDrawable(R.drawable.pinpoint_map);
-			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());
-			this.mapView.getOverlays().add(locationOverlay);
+
+
+			//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);
+
+					// TODO: Read from route_point and draw the route on the map.
+					OverlayItem locationOverlayItem = new OverlayItem(title, "", center);
+					/*Drawable locationMarker = this.getResources().getDrawable(R.drawable.pinpoint_map);
+					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());
+					this.mapView.getOverlays().add(locationOverlay);
+					*/
+				}
+
+			}
+			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(15);
+					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_map);
+					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());
+					this.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();

+ 20 - 0
app/src/main/res/drawable/map.xml

@@ -0,0 +1,20 @@
+<shape 
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="rectangle" >
+
+    <stroke
+        android:width="3dp"
+        android:color="@color/map_border" />
+    <solid android:color="@color/map_background" />
+    <corners
+        android:bottomRightRadius="7dp"
+        android:bottomLeftRadius="7dp"
+        android:topLeftRadius="7dp"
+        android:topRightRadius="7dp"/>
+    <padding
+        android:left="5dp"
+        android:top="5dp"
+        android:right="5dp"
+        android:bottom="5dp" />
+
+</shape>

+ 28 - 4
app/src/main/res/layout/dialog_schedule.xml

@@ -63,6 +63,7 @@
             android:textStyle="bold"/>
 
         <LinearLayout
+            android:id="@+id/ll_dialog_schedule_place"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:layout_margin="8dp"
@@ -80,6 +81,7 @@
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:capitalize="sentences"
+                    android:text="AAA"
                     android:textAppearance="?android:attr/textAppearanceMedium"
                     android:textColor="@color/entry_title"
                     android:textStyle="bold"
@@ -114,6 +116,16 @@
                 android:textStyle="italic"
                 android:visibility="gone"/>
 
+            <TextView
+                android:id="@+id/tv_dialog_schedule_sponsor"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_marginLeft="15dp"
+                android:layout_marginStart="15dp"
+                android:textAppearance="@android:style/TextAppearance.Small"
+                android:textStyle="italic"
+                android:visibility="gone"/>
+
             <LinearLayout
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
@@ -158,17 +170,29 @@
                 android:layout_width="fill_parent"
                 android:layout_height="fill_parent"
                 android:layout_margin="20dp"
+                android:orientation="vertical"
                 android:padding="3dp">
 
                 <org.osmdroid.views.MapView
                     android:id="@+id/mv_dialog_schedule_map"
-                    android:layout_width="fill_parent"
-                    android:layout_height="fill_parent"
-                    android:background="@android:color/black"
+                    android:layout_width="match_parent"
+                    android:layout_height="match_parent"
+                    android:layout_weight=".95"
+                    android:background="@drawable/map"
                     android:padding="1dp"/>
+
+                <TextView
+                    android:id="@+id/tv_dialog_schedule_osm"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:text="@string/schedule_osm"
+                    android:textAlignment="textEnd"
+                    android:textAppearance="@android:style/TextAppearance.Small"
+                    android:textColor="@color/input_border"/>
+
             </LinearLayout>
         </LinearLayout>
 
     </LinearLayout>
 
-</RelativeLayout>
+</RelativeLayout>

+ 2 - 1
app/src/main/res/values-en/strings.xml

@@ -28,7 +28,7 @@
 	<string name="schedule_filter">Search&#8230;</string>
 	<string name="schedule_close">Close</string>
 	<string name="schedule_host">Host: %1$s</string>
-
+        <string name="schedule_osm">® OpenStreetMap contributors</string>
 
 
 	<!-- Day strings -->
@@ -229,5 +229,6 @@
 	<string name="share_with_title">%s - Gasteizko Margolariak</string>
 
 	<string name="accept">Accept</string>
+	<string name="schedule_sponsor">Sponsor: %1$s</string>
 
 </resources>

+ 2 - 0
app/src/main/res/values-eu-rES/strings.xml

@@ -35,6 +35,7 @@
 	<string name="schedule_filter">Bilatu…</string>
 	<string name="schedule_close">Itzali</string>
 	<string name="schedule_host">Antolatu: %1$s</string>
+        <string name="schedule_osm">® Colaboradores OpenStreetMap</string>
 
 
 	<!-- Day strings -->
@@ -234,5 +235,6 @@
 	<string name="share_with_title">%s - Gasteizko Margolariak</string>
 
 	<string name="accept">Aceptar</string>
+    <string name="schedule_sponsor">Patrocina %1$s</string>
 
 </resources>

+ 6 - 2
app/src/main/res/values/color.xml

@@ -20,7 +20,7 @@
     <!--Color for the border of the image-->
     <color name="image_border">#292690</color>
     
-    <!--Color for the menu entries-->
+    <!-- Color for the menu entries -->
     <color name="menu_entry">#ffffff</color>
 
     <!-- Colors for top bar -->
@@ -29,7 +29,7 @@
     <color name="background_bar_gradient">#bdf8fd</color>
     <color name="menu_selected">#ccccff</color>
 
-    <!--Color for input fields-->
+    <!-- Color for input fields -->
     <color name="input_background">#ccddff</color>
     <color name="input_border">#0078ff</color>
     <color name="input_text_color">#0078ff</color>
@@ -38,7 +38,11 @@
     <color name="input_button_color">#cccccc</color>
     <color name="input_button_background_pressed">#446688</color>
 
+    <!-- Color for maps -->
+    <color name="map_border">#0077ff</color>
+    <color name="map_background">#ffffff</color>
 
+    <!--Colors for album covers -->
     <color name="album_border">#111111</color>
     <color name="album_background">#aaaaaa</color>
 

+ 2 - 0
app/src/main/res/values/strings.xml

@@ -39,6 +39,8 @@
 	<string name="schedule_filter">Buscar&#8230;</string>
 	<string name="schedule_close">Cerrar</string>
 	<string name="schedule_host">Organiza %1$s</string>
+	<string name="schedule_sponsor">Patrocina %1$s</string>
+	<string name="schedule_osm">® Colaboradores OpenStreetMap</string>
 
 
 	<!-- Day strings -->