Ver código fonte

Compatibility nwith Android 4.4 and above.

Iñigo Valentin 8 anos atrás
pai
commit
683c925c20
100 arquivos alterados com 240 adições e 240 exclusões
  1. 6 6
      app/build.gradle
  2. 6 5
      app/src/main/AndroidManifest.xml
  3. 10 8
      app/src/main/java/com/ivalentin/margolariak/ActivityFutureLayout.java
  4. 13 6
      app/src/main/java/com/ivalentin/margolariak/AlarmReceiver.java
  5. 0 71
      app/src/main/java/com/ivalentin/margolariak/CustomScrollView.java
  6. 2 0
      app/src/main/java/com/ivalentin/margolariak/DownloadImage.java
  7. 72 51
      app/src/main/java/com/ivalentin/margolariak/HomeLayout.java
  8. 50 18
      app/src/main/java/com/ivalentin/margolariak/LocationLayout.java
  9. 3 3
      app/src/main/java/com/ivalentin/margolariak/MainActivity.java
  10. 6 3
      app/src/main/java/com/ivalentin/margolariak/PostComment.java
  11. 3 1
      app/src/main/java/com/ivalentin/margolariak/ReceiveLocation.java
  12. 11 16
      app/src/main/java/com/ivalentin/margolariak/ScheduleLayout.java
  13. 1 1
      app/src/main/java/com/ivalentin/margolariak/SponsorActivity.java
  14. 53 47
      app/src/main/java/com/ivalentin/margolariak/Sync.java
  15. 4 4
      app/src/main/java/com/ivalentin/margolariak/UsActivity.java
  16. BIN
      app/src/main/res/drawable-hdpi/ic_launcher.png
  17. BIN
      app/src/main/res/drawable-hdpi/ic_notification.png
  18. BIN
      app/src/main/res/drawable-hdpi/social_facebook.png
  19. BIN
      app/src/main/res/drawable-hdpi/social_googleplus.png
  20. BIN
      app/src/main/res/drawable-hdpi/social_instagram.png
  21. BIN
      app/src/main/res/drawable-hdpi/social_mail.png
  22. BIN
      app/src/main/res/drawable-hdpi/social_phone.png
  23. BIN
      app/src/main/res/drawable-hdpi/social_twitter.png
  24. BIN
      app/src/main/res/drawable-hdpi/social_whatsapp.png
  25. BIN
      app/src/main/res/drawable-hdpi/social_youtube.png
  26. BIN
      app/src/main/res/drawable-hdpi/us_activities.png
  27. BIN
      app/src/main/res/drawable-hdpi/us_asociacion.png
  28. BIN
      app/src/main/res/drawable-hdpi/us_cuadrilla.png
  29. BIN
      app/src/main/res/drawable-hdpi/us_transparency.png
  30. BIN
      app/src/main/res/drawable-ldpi/ic_launcher.png
  31. BIN
      app/src/main/res/drawable-ldpi/ic_notification.png
  32. BIN
      app/src/main/res/drawable-ldpi/social_facebook.png
  33. BIN
      app/src/main/res/drawable-ldpi/social_googleplus.png
  34. BIN
      app/src/main/res/drawable-ldpi/social_instagram.png
  35. BIN
      app/src/main/res/drawable-ldpi/social_mail.png
  36. BIN
      app/src/main/res/drawable-ldpi/social_phone.png
  37. BIN
      app/src/main/res/drawable-ldpi/social_twitter.png
  38. BIN
      app/src/main/res/drawable-ldpi/social_whatsapp.png
  39. BIN
      app/src/main/res/drawable-ldpi/social_youtube.png
  40. BIN
      app/src/main/res/drawable-ldpi/us_activities.png
  41. BIN
      app/src/main/res/drawable-ldpi/us_asociacion.png
  42. BIN
      app/src/main/res/drawable-ldpi/us_cuadrilla.png
  43. BIN
      app/src/main/res/drawable-ldpi/us_transparency.png
  44. BIN
      app/src/main/res/drawable-mdpi/ic_launcher.png
  45. BIN
      app/src/main/res/drawable-mdpi/ic_notification.png
  46. BIN
      app/src/main/res/drawable-mdpi/social_facebook.png
  47. BIN
      app/src/main/res/drawable-mdpi/social_googleplus.png
  48. BIN
      app/src/main/res/drawable-mdpi/social_instagram.png
  49. BIN
      app/src/main/res/drawable-mdpi/social_mail.png
  50. BIN
      app/src/main/res/drawable-mdpi/social_phone.png
  51. BIN
      app/src/main/res/drawable-mdpi/social_twitter.png
  52. BIN
      app/src/main/res/drawable-mdpi/social_whatsapp.png
  53. BIN
      app/src/main/res/drawable-mdpi/social_youtube.png
  54. BIN
      app/src/main/res/drawable-mdpi/us_activities.png
  55. BIN
      app/src/main/res/drawable-mdpi/us_asociacion.png
  56. BIN
      app/src/main/res/drawable-mdpi/us_cuadrilla.png
  57. BIN
      app/src/main/res/drawable-mdpi/us_transparency.png
  58. BIN
      app/src/main/res/drawable-nodpi/comment.png
  59. BIN
      app/src/main/res/drawable-nodpi/photo_placeholder_miniature.png
  60. BIN
      app/src/main/res/drawable-nodpi/photo_placeholder_preview.png
  61. BIN
      app/src/main/res/drawable-nodpi/photo_placeholder_thumb.png
  62. 0 0
      app/src/main/res/drawable-nodpi/pinpoint.png
  63. 0 0
      app/src/main/res/drawable-nodpi/pinpoint_end.png
  64. 0 0
      app/src/main/res/drawable-nodpi/pinpoint_route.png
  65. 0 0
      app/src/main/res/drawable-nodpi/pinpoint_start.png
  66. 0 0
      app/src/main/res/drawable-nodpi/schedule_point.png
  67. 0 0
      app/src/main/res/drawable-nodpi/schedule_timeline.png
  68. 0 0
      app/src/main/res/drawable-nodpi/ul.png
  69. BIN
      app/src/main/res/drawable-nodpi/web.png
  70. BIN
      app/src/main/res/drawable-xhdpi/ic_launcher.png
  71. BIN
      app/src/main/res/drawable-xhdpi/ic_notification.png
  72. BIN
      app/src/main/res/drawable-xhdpi/social_facebook.png
  73. BIN
      app/src/main/res/drawable-xhdpi/social_googleplus.png
  74. BIN
      app/src/main/res/drawable-xhdpi/social_instagram.png
  75. BIN
      app/src/main/res/drawable-xhdpi/social_mail.png
  76. BIN
      app/src/main/res/drawable-xhdpi/social_phone.png
  77. BIN
      app/src/main/res/drawable-xhdpi/social_twitter.png
  78. BIN
      app/src/main/res/drawable-xhdpi/social_whatsapp.png
  79. BIN
      app/src/main/res/drawable-xhdpi/social_youtube.png
  80. BIN
      app/src/main/res/drawable-xhdpi/us_activities.png
  81. BIN
      app/src/main/res/drawable-xhdpi/us_asociacion.png
  82. BIN
      app/src/main/res/drawable-xhdpi/us_cuadrilla.png
  83. BIN
      app/src/main/res/drawable-xhdpi/us_transparency.png
  84. BIN
      app/src/main/res/drawable-xxhdpi/ic_launcher.png
  85. BIN
      app/src/main/res/drawable-xxhdpi/ic_notification.png
  86. BIN
      app/src/main/res/drawable-xxhdpi/social_facebook.png
  87. BIN
      app/src/main/res/drawable-xxhdpi/social_googleplus.png
  88. BIN
      app/src/main/res/drawable-xxhdpi/social_instagram.png
  89. BIN
      app/src/main/res/drawable-xxhdpi/social_mail.png
  90. BIN
      app/src/main/res/drawable-xxhdpi/social_phone.png
  91. BIN
      app/src/main/res/drawable-xxhdpi/social_twitter.png
  92. BIN
      app/src/main/res/drawable-xxhdpi/social_whatsapp.png
  93. BIN
      app/src/main/res/drawable-xxhdpi/social_youtube.png
  94. BIN
      app/src/main/res/drawable-xxhdpi/us_activities.png
  95. BIN
      app/src/main/res/drawable-xxhdpi/us_asociacion.png
  96. BIN
      app/src/main/res/drawable-xxhdpi/us_cuadrilla.png
  97. BIN
      app/src/main/res/drawable-xxhdpi/us_transparency.png
  98. BIN
      app/src/main/res/drawable-xxxhdpi/ic_launcher.png
  99. BIN
      app/src/main/res/drawable-xxxhdpi/ic_notification.png
  100. BIN
      app/src/main/res/drawable-xxxhdpi/social_facebook.png

+ 6 - 6
app/build.gradle

@@ -1,13 +1,13 @@
 apply plugin: 'com.android.application'
 
 android {
-    compileSdkVersion 23
+    compileSdkVersion 28
     buildToolsVersion '27.0.3'
 
     defaultConfig {
         applicationId "com.ivalentin.margolariak"
-        minSdkVersion 23
-        targetSdkVersion 23
+        minSdkVersion 19
+        targetSdkVersion 28
         multiDexEnabled true
     }
 
@@ -31,8 +31,8 @@ android {
 
 dependencies {
     //noinspection GradleDynamicVersion
-    compile 'com.android.support:multidex:1.0.1'
-    compile 'org.osmdroid:osmdroid-android:5.6.5@aar'
+    api 'com.android.support:multidex:1.0.3'
+    api 'org.osmdroid:osmdroid-android:5.6.5@aar'
 }
 
 
@@ -42,4 +42,4 @@ allprojects {
         google()
         jcenter()
     }
-}
+}

+ 6 - 5
app/src/main/AndroidManifest.xml

@@ -1,9 +1,10 @@
 <?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
-          xmlns:tools="http://schemas.android.com/tools"
-          package="com.ivalentin.margolariak"
-    android:versionCode="27"
-    android:versionName="4" >
+<manifest 
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    package="com.ivalentin.margolariak"
+    android:versionCode="30"
+    android:versionName="4.3" >
 
     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

+ 10 - 8
app/src/main/java/com/ivalentin/margolariak/ActivityFutureLayout.java

@@ -52,11 +52,13 @@ import org.osmdroid.views.overlay.Polyline;
  */
 public class ActivityFutureLayout extends Fragment {
 
+	private View view;
+
 	@Override
 	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
 
 		//Load the layout
-		View view = inflater.inflate(R.layout.fragment_layout_activity_future, container, false);
+		view = inflater.inflate(R.layout.fragment_layout_activity_future, container, false);
 
 		//Get bundled id
 		Bundle bundle = this.getArguments();
@@ -334,16 +336,16 @@ public class ActivityFutureLayout extends Fragment {
 					// Create path
 					Polyline line = new Polyline();
 					line.setPoints(points);
-					line.setColor(getResources().getColor(R.color.map_route, null));
+					line.setColor(getResources().getColor(R.color.map_route));
 					line.setWidth(30.0f);
 					mapView.getOverlays().add(line);
 
 					// Set markers
 					OverlayItem startOverlay = new OverlayItem(title, title, firstPoint);
-					Drawable startMarker = this.getResources().getDrawable(R.drawable.pinpoint_start, null);
+					Drawable startMarker = this.getResources().getDrawable(R.drawable.pinpoint_start);
 					startOverlay.setMarker(startMarker);
 					OverlayItem endOverlay = new OverlayItem(title, title, lastPoint);
-					Drawable endMarker = this.getResources().getDrawable(R.drawable.pinpoint_end, null);
+					Drawable endMarker = this.getResources().getDrawable(R.drawable.pinpoint_end);
 					endOverlay.setMarker(endMarker);
 					final ArrayList<OverlayItem> markers = new ArrayList<>();
 					markers.add(startOverlay);
@@ -356,7 +358,7 @@ public class ActivityFutureLayout extends Fragment {
 					        public boolean onItemLongPress(final int index, final OverlayItem item) {
 					                return true;
 					        }
-					  }, getContext());
+					  }, mapView.getContext());
 					mapView.getOverlays().add(markersOverlay);
 
 				}
@@ -374,7 +376,7 @@ public class ActivityFutureLayout extends Fragment {
 					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, null);
+					Drawable locationMarker = this.getResources().getDrawable(R.drawable.pinpoint);
 					locationOverlayItem.setMarker(locationMarker);
 					final ArrayList<OverlayItem> items = new ArrayList<>();
 					items.add(locationOverlayItem);
@@ -386,7 +388,7 @@ public class ActivityFutureLayout extends Fragment {
 								public boolean onItemLongPress(final int index, final OverlayItem item) {
 									return true;
 								}
-							}, getContext());
+							}, mapView.getContext());
 					mapView.getOverlays().add(locationOverlay);
 				}
 				placeCursor.close();
@@ -437,7 +439,7 @@ public class ActivityFutureLayout extends Fragment {
 	 */
 	@Override
 	public void onResume() {
-		Configuration.getInstance().load(getContext(), PreferenceManager.getDefaultSharedPreferences(getContext()));
+		Configuration.getInstance().load(view.getContext(), PreferenceManager.getDefaultSharedPreferences(view.getContext()));
 		super.onResume();
 	}
 

+ 13 - 6
app/src/main/java/com/ivalentin/margolariak/AlarmReceiver.java

@@ -17,6 +17,7 @@ import android.database.sqlite.SQLiteDatabaseLockedException;
 import android.graphics.BitmapFactory;
 import android.media.RingtoneManager;
 import android.content.BroadcastReceiver;
+import android.os.Build;
 import android.util.Log;
 
 /**
@@ -36,7 +37,7 @@ public class AlarmReceiver extends BroadcastReceiver {
      * @param context Context of the activity or application
      * @param intent Receiver intent
      * 
-     * @see android.content.BroadcastReceiver#onReceive(android.content.Context, android.content.Intent)
+     * @see BroadcastReceiver#onReceive(Context, Intent)
      */
     @Override
 	@SuppressWarnings("deprecation")
@@ -144,10 +145,12 @@ public class AlarmReceiver extends BroadcastReceiver {
 								.setAutoCancel(true)
 								.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher))
 								.setVibrate((new long[]{400, 400, 400}))
-								.setColor(context.getResources().getColor(R.color.background_notification))
 								.setSubText(context.getString(R.string.app_name))
 								.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
 								.setContentText(text);
+						if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+							mBuilder.setColor(context.getResources().getColor(R.color.background_notification));
+						}
 
 						// Creates an intent for an Activity to be launched from the notification.
 						resultIntent = new Intent(context, MainActivity.class);
@@ -168,7 +171,9 @@ public class AlarmReceiver extends BroadcastReceiver {
 						mBuilder.setContentIntent(resultPendingIntent);
 
 						//Actually send the notification.
-						mNotificationManager.notify(id, mBuilder.build());
+						if (mNotificationManager != null) {
+							mNotificationManager.notify(id, mBuilder.build());
+						}
 
 					}
 					cursor.close();
@@ -198,7 +203,7 @@ public class AlarmReceiver extends BroadcastReceiver {
 		 * @param in String to be decoded.
 		 * @return Decoded string.
 		 */
-		static String decode(final String in){
+		private static String decode(final String in){
 			String working = in;
 			int index = working.indexOf("\\u");
 			while(index > -1){
@@ -233,8 +238,10 @@ public class AlarmReceiver extends BroadcastReceiver {
 			PendingIntent alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
 
 			//Set the alarm cycle.
-			//TODO: Set the most appropiate interval
-			alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, GM.PERIOD_SYNC.FESTIVALS, GM.PERIOD_SYNC.FESTIVALS, alarmIntent);
+			//TODO: Set the most appropriate interval
+			if (alarmMgr != null) {
+				alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, GM.PERIOD_SYNC.FESTIVALS, GM.PERIOD_SYNC.FESTIVALS, alarmIntent);
+			}
 
 			// Enable SampleBootReceiver to automatically restart the alarm when the device is rebooted.
 			ComponentName receiver = new ComponentName(context, BootReceiver.class);

+ 0 - 71
app/src/main/java/com/ivalentin/margolariak/CustomScrollView.java

@@ -1,71 +0,0 @@
-package com.ivalentin.margolariak;
-
-import android.content.Context;
-import android.util.AttributeSet;
-import android.view.MotionEvent;
-import android.widget.ScrollView;
-
-/**
- * An extended ScrollView. 
- * It allows to be swept from the left to open the application menu.
- * 
- * @author Iñigo Valentin
- * 
- * @see ScrollView
- *
- */
-public class CustomScrollView extends ScrollView{
-
-	/**
-	 * Constructor.
-	 * 
-	 * @param context The context of the app or Activity.
-	 */
-	public CustomScrollView(Context context) {
-		super(context);
-	}
-
-
-	/**
-	 * Constructor.
-	 * 
-	 * @param context The context of the app or Activity.
-	 * @param attrs Attributes.
-	 */
-	public CustomScrollView(Context context, AttributeSet attrs) {
-		super(context, attrs);
-	}
-
-
-	/**
-	 * Constructor.
-	 * 
-	 * @param context The context of the app or Activity.
-	 * @param attrs Attributes.
-	 * @param defStyle Default style.
-	 */
-	public CustomScrollView(Context context, AttributeSet attrs, int defStyle) {
-		super(context, attrs, defStyle);
-	}
-
-
-	/**
-	 * Overrides the default onTouchListener. 
-	 * 
-	 * If the motion is in the leftmost part of the screen, the event is not 
-	 * passed along and the menu is shown.
-	 * 
-	 * @see android.widget.ScrollView#onTouchEvent(android.view.MotionEvent)
-	 * 
-	 * @param ev The MotionEvent triggering the action
-	 * 
-	 * @return True if the app handles the motion (i.e. to slide), false otherwise (normal event)
-	 */
-	@Override
-	public boolean onTouchEvent(MotionEvent ev) {
-		int width = this.getWidth();
-		super.onTouchEvent(ev);
-		return ev.getX() >= (float) width / 10;
-	}
-
-}

+ 2 - 0
app/src/main/java/com/ivalentin/margolariak/DownloadImage.java

@@ -1,5 +1,6 @@
 package com.ivalentin.margolariak;
 
+import android.annotation.SuppressLint;
 import android.os.AsyncTask;
 import android.util.Log;
 import android.view.View;
@@ -24,6 +25,7 @@ class DownloadImage extends AsyncTask<Void, Void, Void> {
 
 	private final String file;
 	private final String path;
+	@SuppressLint("StaticFieldLeak")
 	private final ImageView iv;
 	private final int size;
 

+ 72 - 51
app/src/main/java/com/ivalentin/margolariak/HomeLayout.java

@@ -38,6 +38,8 @@ import android.widget.LinearLayout;
 import android.widget.TextView;
 import android.widget.Toast;
 
+import static android.os.Build.VERSION.SDK_INT;
+
 /**
  * Section that will be seen when the app is started. 
  * Contains info from almost every other section.
@@ -47,6 +49,7 @@ import android.widget.Toast;
  * @see Fragment
  *
  */
+@SuppressWarnings("ResultOfMethodCallIgnored")
 public class HomeLayout extends Fragment implements LocationListener {
 
 	//The location manager
@@ -79,20 +82,24 @@ public class HomeLayout extends Fragment implements LocationListener {
 		view = inflater.inflate(R.layout.fragment_layout_home, container, false);
 
 		//Request storage permissions if not set
-		if (!checkStoragePermission()) {
-			requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, GM.PERMISSION.STORAGE);
+		if (!getStoragePermission()){
+			askStoragePermission();
 		}
-
-		//Request location permissions if not set
-		if (!checkLocationPermission()) {
-			requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, GM.PERMISSION.LOCATION);
+		if (!getLocationPermission()){
+			askLocationPermission();
 		}
 
+
 		//Set Location manager
 		locationManager = (LocationManager) view.getContext().getSystemService(Context.LOCATION_SERVICE);
-		if (checkLocationPermission()) {
-			locationManager.requestLocationUpdates(locationManager.getBestProvider(new Criteria(), true), GM.LOCATION.ACCURACY.TIME, GM.LOCATION.ACCURACY.SPACE, this);
-			onLocationChanged(locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER));
+		if (getLocationPermission()) {
+			try {
+				locationManager.requestLocationUpdates(locationManager.getBestProvider(new Criteria(), true), GM.LOCATION.ACCURACY.TIME, GM.LOCATION.ACCURACY.SPACE, this);
+				onLocationChanged(locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER));
+			}
+			catch (SecurityException ex){
+				Log.e("HOME_LAYOUT", "Missing location permission: " + ex.toString());
+			}
 		}
 
 		//Set the title
@@ -124,15 +131,13 @@ public class HomeLayout extends Fragment implements LocationListener {
 
 	/**
 	 * Populates the schedule sections of the home screen.
-	 *
-	 * @return The number of entries shown.
 	 */
-	private int setUpSchedule(int gm, View view) {
+	private void setUpSchedule(int gm, View view) {
 		int count = 0;
 
 		SharedPreferences data = view.getContext().getSharedPreferences(GM.DATA.DATA, Context.MODE_PRIVATE);
 		if (!data.getBoolean(GM.DATA.KEY.LABLANCA, GM.DATA.DEFAULT.LABLANCA)) {
-			return count;
+			return;
 		}
 
 		SQLiteDatabase db = SQLiteDatabase.openDatabase(getActivity().getDatabasePath(GM.DB.NAME).getAbsolutePath(), null, SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READONLY);
@@ -293,7 +298,6 @@ public class HomeLayout extends Fragment implements LocationListener {
 		}
 
 		db.close();
-		return count;
 	}
 
 	/**
@@ -398,12 +402,9 @@ public class HomeLayout extends Fragment implements LocationListener {
 
 	/**
 	 * Populates the La Blanca section of the home screen.
-	 *
-	 * @return True if the section has been shown, false otherwise.
 	 */
-	private boolean setUpLablanca(View view) {
+	private void setUpLablanca(View view) {
 		SharedPreferences preferences = view.getContext().getSharedPreferences(GM.DATA.DATA, Context.MODE_PRIVATE);
-		Boolean set = false;
 		if (preferences.getBoolean(GM.DATA.KEY.LABLANCA, GM.DATA.DEFAULT.LABLANCA)) {
 			LinearLayout llSection = (LinearLayout) view.findViewById(R.id.ll_home_section_lablanca);
 			TextView tvText = (TextView) view.findViewById(R.id.tv_home_section_lablanca_text);
@@ -437,8 +438,6 @@ public class HomeLayout extends Fragment implements LocationListener {
 					tvText.setText(shortText);
 				}
 
-				set = true;
-
 				//Set image
 				String image = cursor.getString(1);
 				if (image != null && image.length() > 0){
@@ -467,15 +466,15 @@ public class HomeLayout extends Fragment implements LocationListener {
 
 
 		}
-		return set;
 	}
 
 	/**
 	 * Populates the Location section of the home screen.
 	 *
-	 * @return True if the section has been shown, false otherwise.
+	 * @param location Last known location.
+	 * @param view The parent view.
 	 */
-	private boolean setUpLocation(Location location, View view) {
+	private void setUpLocation(Location location, View view) {
 		try {
 
 			Double lat, lon;
@@ -486,7 +485,6 @@ public class HomeLayout extends Fragment implements LocationListener {
 			if (cursor.getCount() == 0){
 				cursor.close();
 				db.close();
-				return false;
 			}
 			else {
 				cursor.moveToFirst();
@@ -500,18 +498,16 @@ public class HomeLayout extends Fragment implements LocationListener {
 				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 {
+				}
+				else {
 					text.setText(String.format(getString(R.string.home_section_location_text_long), String.format(Locale.US, "%.02f", distance)));
 				}
 
-				return true;
 			}
 		}
 		catch (Exception ex){
 			Log.e("HOME_LAYOUT", "Couldn't set up home location section: " + ex.toString());
 		}
-
-		return false;
 	}
 
 	/**
@@ -519,9 +515,9 @@ public class HomeLayout extends Fragment implements LocationListener {
 	 * Loads four photos.
 	 * Tapping them takes to the respective album, tapping anywhere else, to the gallery section.
 	 *
-	 * @return The number of entries shown
+	 * @param view The parent view.
 	 */
-	private int setUpGallery(View view) {
+	private void setUpGallery(View view) {
 		int counter = 0;
 
 		//Set onClick listener of section
@@ -599,7 +595,6 @@ public class HomeLayout extends Fragment implements LocationListener {
 		cursor.close();
 		db.close();
 
-		return counter;
 	}
 
 	/**
@@ -607,10 +602,9 @@ public class HomeLayout extends Fragment implements LocationListener {
 	 * Makes the section visible and adds two rows with the two last activities.
 	 * Tapping them takes to the activity, tapping anywhere else, to the activities section.
 	 *
-	 * @return The number of entries shown
+	 * @param view The parent view.
 	 */
-	private int setUpPastActivities(View view) {
-		int counter = 0;
+	private void setUpPastActivities(View view) {
 		String lang = GM.getLang();
 
 		//Get data from the database of the future activities
@@ -723,14 +717,12 @@ public class HomeLayout extends Fragment implements LocationListener {
 			});
 
 			llList.addView(entry);
-			counter++;
 		}
 
 		//Close db
 		cursor.close();
 		db.close();
 
-		return counter;
 	}
 
 	/**
@@ -866,10 +858,9 @@ public class HomeLayout extends Fragment implements LocationListener {
 	 * Populates the Blog section of the home screen.
 	 * Adds two rows with the two latest posts. Tapping them takes to the post, tapping anywhere else, to the blog section.
 	 *
-	 * @return The number of entries shown
+	 * @param view The parent view.
 	 */
-	private int setUpBlog(View view) {
-		int counter = 0;
+	private void setUpBlog(View view) {
 		String lang = GM.getLang();
 
 		LinearLayout llBlog = (LinearLayout) view.findViewById(R.id.ll_home_section_blog);
@@ -968,14 +959,12 @@ public class HomeLayout extends Fragment implements LocationListener {
 
 			llList.addView(entry);
 
-			counter++;
 		}
 
 		//Close database
 		cursor.close();
 		db.close();
 
-		return counter;
 	}
 
 	/**
@@ -1041,7 +1030,7 @@ public class HomeLayout extends Fragment implements LocationListener {
 	 */
 	@Override
 	public void onPause() {
-		if (checkLocationPermission()) {
+		if (getLocationPermission()) {
 			locationManager.removeUpdates(this);
 		}
 		super.onPause();
@@ -1056,7 +1045,7 @@ public class HomeLayout extends Fragment implements LocationListener {
 	@Override
 	public void onDestroy() {
 		try {
-			if (checkLocationPermission()) {
+			if (getLocationPermission()) {
 				locationManager.removeUpdates(this);
 			}
 		}
@@ -1075,26 +1064,58 @@ public class HomeLayout extends Fragment implements LocationListener {
 	 */
 	@Override
 	public void onResume(){
-		if (checkLocationPermission()) {
-			locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, this);
+		if (getLocationPermission()) {
+			try{
+				locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, GM.LOCATION.ACCURACY.TIME, GM.LOCATION.ACCURACY.SPACE, this);
+			}
+			catch (SecurityException ex){
+				Log.e("HOME_LAYOUT", "Missing location permission: " + ex.toString());
+			}
 		}
 		super.onResume();
 	}
 
 
 	/**
-	 * Checks app permission to write device storage, user for OSM cache.
+	 * Checks app permission to write device storage, user for OSM cache
+	 * and photo downloads.
+	 * If the SDK version doesn't handle individual permissions, it will always
+	 * return true.
+	 *
 	 * @return true if the permission has been granted, false otherwise.
 	 */
-        private boolean checkStoragePermission(){
-                return getContext().checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
-        }
+	private boolean getStoragePermission() {
+		return SDK_INT < 23 || getContext().checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
+	}
+
+
+	/**
+	 * Asks for storage permissions. For SDK under 23, it does nothing.
+	 */
+	private void askStoragePermission(){
+		if (SDK_INT >= 23){
+			requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, GM.PERMISSION.STORAGE);
+		}
+	}
 
 	/**
 	 * Checks app permission to access the user location.
+	 * If the SDK version doesn't handle individual permissions, it will always
+	 * return true.
+	 *
 	 * @return true if the permission has been granted, false otherwise.
 	 */
-	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;
+	private boolean getLocationPermission() {
+		return SDK_INT < 23 || getContext().checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && getContext().checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED;
+	}
+
+
+	/**
+	 * Asks for location permissions. For SDK under 23, it does nothing.
+	 */
+	private void askLocationPermission(){
+		if (SDK_INT >= 23){
+			requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, GM.PERMISSION.LOCATION);
+		}
 	}
 }

+ 50 - 18
app/src/main/java/com/ivalentin/margolariak/LocationLayout.java

@@ -3,6 +3,7 @@ package com.ivalentin.margolariak;
 import java.util.Locale;
 import java.util.ArrayList;
 
+import android.Manifest;
 import android.app.Activity;
 import android.content.Context;
 import android.content.pm.PackageManager;
@@ -28,6 +29,8 @@ import org.osmdroid.views.MapView;
 import org.osmdroid.views.overlay.ItemizedIconOverlay;
 import org.osmdroid.views.overlay.OverlayItem;
 
+import static android.os.Build.VERSION.SDK_INT;
+
 /**
  * Section that shows a map with the location of Gasteizko Margolariak.
  *
@@ -59,7 +62,6 @@ public class LocationLayout extends Fragment implements LocationListener {
 
 			if (mapView != null) {
 				if (refreshLocation()) {
-					
 					OverlayItem locationOverlayItem = new OverlayItem("Gasteizko Margolariak", "", gmLocation);
 					locationOverlayItem.setMarker(locationMarker);
 					final ArrayList<OverlayItem> items = new ArrayList<>();
@@ -72,7 +74,7 @@ public class LocationLayout extends Fragment implements LocationListener {
 								public boolean onItemLongPress(final int index, final OverlayItem item) {
 									return true;
 								}
-							}, getContext());
+							}, mapView.getContext());
 					mapView.getOverlays().add(locationOverlay);
 				}
 			}
@@ -96,11 +98,22 @@ public class LocationLayout extends Fragment implements LocationListener {
 		//Get the view
 		v = inflater.inflate(R.layout.fragment_layout_location, container, false);
 
+		// Ask for location permissions.
+		if (!getLocationPermission()){
+			askLocationPermission();
+		}
+
 		//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);
+
+		if (getLocationPermission()){
+			try{
+				locationManager.requestSingleUpdate(LocationManager.GPS_PROVIDER, this, null);
+				locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, GM.LOCATION.ACCURACY.TIME, GM.LOCATION.ACCURACY.SPACE, this);
+			}
+			catch (SecurityException ex){
+				Log.e("LOCATION_LAYOUT", "Missing location permission: " + ex.toString());
+			}
 		}
 
 		//Set the title
@@ -118,7 +131,7 @@ public class LocationLayout extends Fragment implements LocationListener {
 		IMapController mapController = mapView.getController();
 		mapController.setZoom(17);
 		mapController.setCenter(gmLocation);
-		this.locationMarker = this.getResources().getDrawable(R.drawable.pinpoint, null);
+		this.locationMarker = this.getResources().getDrawable(R.drawable.pinpoint);
 
 		//Return the view
 		return v;
@@ -133,8 +146,13 @@ public class LocationLayout extends Fragment implements LocationListener {
 	 */
 	@Override
 	public void onResume() {
-		if (checkLocationPermission()){
-			locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, GM.LOCATION.ACCURACY.TIME, GM.LOCATION.ACCURACY.SPACE, this);
+		if (getLocationPermission()) {
+			try{
+				locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, GM.LOCATION.ACCURACY.TIME, GM.LOCATION.ACCURACY.SPACE, this);
+			}
+			catch (SecurityException ex){
+				Log.e("LOCATION_LAYOUT", "Missing location permission: " + ex.toString());
+			}
 		}
 		super.onResume();
 		markerHandler.post(resetMarker);
@@ -148,11 +166,10 @@ public class LocationLayout extends Fragment implements LocationListener {
 	 */
 	@Override
 	public void onPause(){
-		if (checkLocationPermission()) {
+		if (getLocationPermission()) {
 			locationManager.removeUpdates(this);
 		}
 		super.onPause();
-
 		markerHandler.removeCallbacks(resetMarker);
 	}
 
@@ -165,11 +182,15 @@ public class LocationLayout extends Fragment implements LocationListener {
 	 */
 	@Override
 	public void onDestroy() {
-		super.onDestroy();
-		if (checkLocationPermission()) {
-			locationManager.removeUpdates(this);
+		try {
+			if (getLocationPermission()) {
+				locationManager.removeUpdates(this);
+			}
 		}
-
+		catch (Exception ex){
+			Log.e("LOCATION_LAYOUT", "Unable to stop location manager on destroy: " + ex.toString());
+		}
+		super.onDestroy();
 		markerHandler.removeCallbacks(resetMarker);
 	}
 
@@ -246,12 +267,23 @@ public class LocationLayout extends Fragment implements LocationListener {
 
 	/**
 	 * Checks app permission to access the user location.
-	 * @return true if the permission has been granted, false otherwise.
+	 * If the SDK version doesn't handle individual permissions, it will always
+	 * return true.
 	 *
-	 * @see android.app.Fragment#onResume()
+	 * @return true if the permission has been granted, false otherwise.
 	 */
-	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;
+	private boolean getLocationPermission() {
+		return SDK_INT < 23 || getContext().checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && getContext().checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED;
+	}
+
+
+	/**
+	 * Asks for location permissions. For SDK under 23, it does nothing.
+	 */
+	private void askLocationPermission(){
+		if (SDK_INT >= 23){
+			requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, GM.PERMISSION.LOCATION);
+		}
 	}
 
 

+ 3 - 3
app/src/main/java/com/ivalentin/margolariak/MainActivity.java

@@ -53,7 +53,7 @@ public class MainActivity extends Activity {
 	private final Handler locationHandler = new Handler();
 
 	// Code to check for location updates
-	private MainActivity activity = this;
+	private final MainActivity activity = this;
 	private final Runnable checkForLocation = new Runnable() {
 		@Override
 		public void run() {
@@ -91,7 +91,7 @@ public class MainActivity extends Activity {
 	 *
 	 * @return String array. Index 0 has the title of the section. Index 1 has the URL.
 	 */
-	public String[] getShareLink(){
+	private String[] getShareLink(){
 		return(new String[]{shareTitle, shareURL});
 	}
 
@@ -481,7 +481,7 @@ public class MainActivity extends Activity {
 					});
 
 					//Set the icon
-					dialogIcon = getResources().getDrawable(R.drawable.ic_launcher, null);
+					dialogIcon = getResources().getDrawable(R.drawable.ic_launcher);
 					if (dialogIcon != null) {
 						dialogIcon.setBounds(0, 0, (int) (tvDialogTitle.getTextSize() * 1.4), (int) (tvDialogTitle.getTextSize() * 1.4));
 					}

+ 6 - 3
app/src/main/java/com/ivalentin/margolariak/PostComment.java

@@ -1,5 +1,6 @@
 package com.ivalentin.margolariak;
 
+import android.annotation.SuppressLint;
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.os.AsyncTask;
@@ -31,12 +32,14 @@ class PostComment extends AsyncTask<String, String, Integer> {
 	//Elements passed from fragments
 	private final String type, user, text, language;
 	private String userCode;
+	@SuppressLint("StaticFieldLeak")
 	private final LinearLayout list, form;
 	private final int id;
+	@SuppressLint("StaticFieldLeak")
 	private final Context context;
-
-	//Elements calculated here
+	@SuppressLint("StaticFieldLeak")
 	private Button btSend;
+	@SuppressLint("StaticFieldLeak")
 	private ProgressBar pb;
 
 	private int code = 404;
@@ -212,4 +215,4 @@ class PostComment extends AsyncTask<String, String, Integer> {
 		btSend.setVisibility(View.VISIBLE);
 		pb.setVisibility(View.GONE);
 	}
-}
+}

+ 3 - 1
app/src/main/java/com/ivalentin/margolariak/ReceiveLocation.java

@@ -1,5 +1,6 @@
 package com.ivalentin.margolariak;
 
+import android.annotation.SuppressLint;
 import android.app.Activity;
 import android.database.sqlite.SQLiteDatabase;
 import android.os.AsyncTask;
@@ -24,7 +25,8 @@ import java.net.URL;
 
 class ReceiveLocation extends AsyncTask<Void, Void, Void> {
 
-	private MainActivity activity;
+	@SuppressLint("StaticFieldLeak")
+	private final MainActivity activity;
 	private boolean report = false;
 
 	/**

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

@@ -81,7 +81,7 @@ public class ScheduleLayout extends Fragment{
 		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);
+				ScrollView sv = (ScrollView) v.findViewById(R.id.sv_schedule);
 				sv.invalidate();
 			}
 		});
@@ -178,9 +178,7 @@ public class ScheduleLayout extends Fragment{
 	 * @param schedule GM.SCHEDULE.GM or GM.SCHEDULE.CITY
 	 */
 	//Views are added from a loop: I can't specify the parent when inflating.
-	private int populateSchedule(final int schedule) {
-
-		int eventCount = 0;
+	private void populateSchedule(final int schedule) {
 
 		//Hide or show buttons
 		Button btNext = (Button) view.findViewById(R.id.bt_schedule_r);
@@ -198,7 +196,7 @@ public class ScheduleLayout extends Fragment{
 
 		//If there are no events,return now
 		if (selected < 0 || selected >= dateCount) {
-			return eventCount;
+			return;
 		}
 
 		//Search filter
@@ -260,7 +258,7 @@ public class ScheduleLayout extends Fragment{
 			c.setTime(sdf.parse(dates[selected]));
 		} catch (Exception ex) {
 			Log.e("SCHEDULE_LAYOUT", "Date parsing error: " + ex.toString());
-			return eventCount;
+			return;
 		}
 		c.add(Calendar.DATE, 1);  // number of days to add
 		String endDate = sdf.format(c.getTime());
@@ -297,7 +295,6 @@ public class ScheduleLayout extends Fragment{
 		list.removeAllViews();
 
 		while (cursor.moveToNext()) {
-			eventCount++;
 
 			entry = (LinearLayout) factory.inflate(R.layout.row_schedule, list, false);
 
@@ -368,8 +365,6 @@ public class ScheduleLayout extends Fragment{
 			Log.e("SCHEDULE_LAYOUT", "Culdn't get scrollview to scroll: " + ex.toString());
 		}
 
-		return eventCount;
-
 	}
 
 	/**
@@ -581,16 +576,16 @@ public class ScheduleLayout extends Fragment{
 					// Create path
 					Polyline line = new Polyline();
 					line.setPoints(points);
-					line.setColor(getResources().getColor(R.color.map_route, null));
+					line.setColor(getResources().getColor(R.color.map_route));
 					line.setWidth(30.0f);
 					mapView.getOverlays().add(line);
 
 					// Set markers
 					OverlayItem startOverlay = new OverlayItem(title, title, firstPoint);
-					Drawable startMarker = this.getResources().getDrawable(R.drawable.pinpoint_start, null);
+					Drawable startMarker = this.getResources().getDrawable(R.drawable.pinpoint_start);
 					startOverlay.setMarker(startMarker);
 					OverlayItem endOverlay = new OverlayItem(title, title, lastPoint);
-					Drawable endMarker = this.getResources().getDrawable(R.drawable.pinpoint_end, null);
+					Drawable endMarker = this.getResources().getDrawable(R.drawable.pinpoint_end);
 					endOverlay.setMarker(endMarker);
 					final ArrayList<OverlayItem> markers = new ArrayList<>();
 					markers.add(startOverlay);
@@ -603,7 +598,7 @@ public class ScheduleLayout extends Fragment{
 						public boolean onItemLongPress(final int index, final OverlayItem item) {
 							return true;
 						}
-					  }, getContext());
+					  }, view.getContext());
 					mapView.getOverlays().add(markersOverlay);
 
 				}
@@ -621,7 +616,7 @@ public class ScheduleLayout extends Fragment{
 					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, null);
+					Drawable locationMarker = this.getResources().getDrawable(R.drawable.pinpoint);
 					locationOverlayItem.setMarker(locationMarker);
 					final ArrayList<OverlayItem> items = new ArrayList<>();
 					items.add(locationOverlayItem);
@@ -633,7 +628,7 @@ public class ScheduleLayout extends Fragment{
 								public boolean onItemLongPress(final int index, final OverlayItem item) {
 									return true;
 								}
-							}, getContext());
+							}, view.getContext());
 					mapView.getOverlays().add(locationOverlay);
 				}
 				placeCursor.close();
@@ -699,7 +694,7 @@ public class ScheduleLayout extends Fragment{
 	 */
 	@Override
 	public void onResume() {
-		Configuration.getInstance().load(getContext(), PreferenceManager.getDefaultSharedPreferences(getContext()));
+		Configuration.getInstance().load(view.getContext(), PreferenceManager.getDefaultSharedPreferences(view.getContext()));
 		super.onResume();
 	}
 

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

@@ -258,7 +258,7 @@ public class SponsorActivity extends Activity {
 	 *
 	 * @see Activity#finish()
 	 */
-	public void finish(View v){
+	public void finish(@SuppressWarnings("unused") View v){
 		finish();
 	}
 

+ 53 - 47
app/src/main/java/com/ivalentin/margolariak/Sync.java

@@ -13,6 +13,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.regex.Pattern;
 
+import android.annotation.SuppressLint;
 import android.app.Activity;
 import android.app.Dialog;
 import android.content.Context;
@@ -46,15 +47,20 @@ import org.json.*;
  */
 class Sync extends AsyncTask<Void, Void, Void> {
 	
-	private final Context myContextRef;
+	@SuppressLint("StaticFieldLeak")
+	private final Context ctx;
+	@SuppressLint("StaticFieldLeak")
 	private ProgressBar pbSync;
+	@SuppressLint("StaticFieldLeak")
 	private ImageView ivSync;
 	private Dialog dialog;
+	@SuppressLint("StaticFieldLeak")
 	private MainActivity activity;
 	private int fg;
 	private String strings[];
 	private boolean doProgress = false;
 	private long millis = 0;
+	@SuppressLint("StaticFieldLeak")
 	private TextView tv;
 	
 	
@@ -78,21 +84,21 @@ class Sync extends AsyncTask<Void, Void, Void> {
 			//Show the dialog and assign the elements on it
 			dialog.show();
 			strings = new String[15];
-			strings[0] = myContextRef.getString(R.string.dialog_sync_text_0);
-			strings[1] = myContextRef.getString(R.string.dialog_sync_text_1);
-			strings[2] = myContextRef.getString(R.string.dialog_sync_text_2);
-			strings[3] = myContextRef.getString(R.string.dialog_sync_text_3);
-			strings[4] = myContextRef.getString(R.string.dialog_sync_text_4);
-			strings[5] = myContextRef.getString(R.string.dialog_sync_text_5);
-			strings[6] = myContextRef.getString(R.string.dialog_sync_text_6);
-			strings[7] = myContextRef.getString(R.string.dialog_sync_text_7);
-			strings[8] = myContextRef.getString(R.string.dialog_sync_text_8);
-			strings[9] = myContextRef.getString(R.string.dialog_sync_text_9);
-			strings[10] = myContextRef.getString(R.string.dialog_sync_text_10);
-			strings[11] = myContextRef.getString(R.string.dialog_sync_text_11);
-			strings[12] = myContextRef.getString(R.string.dialog_sync_text_12);
-			strings[13] = myContextRef.getString(R.string.dialog_sync_text_13);
-			strings[14] = myContextRef.getString(R.string.dialog_sync_text_0); //In case I get a 13;
+			strings[0] = ctx.getString(R.string.dialog_sync_text_0);
+			strings[1] = ctx.getString(R.string.dialog_sync_text_1);
+			strings[2] = ctx.getString(R.string.dialog_sync_text_2);
+			strings[3] = ctx.getString(R.string.dialog_sync_text_3);
+			strings[4] = ctx.getString(R.string.dialog_sync_text_4);
+			strings[5] = ctx.getString(R.string.dialog_sync_text_5);
+			strings[6] = ctx.getString(R.string.dialog_sync_text_6);
+			strings[7] = ctx.getString(R.string.dialog_sync_text_7);
+			strings[8] = ctx.getString(R.string.dialog_sync_text_8);
+			strings[9] = ctx.getString(R.string.dialog_sync_text_9);
+			strings[10] = ctx.getString(R.string.dialog_sync_text_10);
+			strings[11] = ctx.getString(R.string.dialog_sync_text_11);
+			strings[12] = ctx.getString(R.string.dialog_sync_text_12);
+			strings[13] = ctx.getString(R.string.dialog_sync_text_13);
+			strings[14] = ctx.getString(R.string.dialog_sync_text_0); //In case I get a 13;
 			tv = (TextView) dialog.findViewById(R.id.tv_dialog_sync_text);
 			int idx = (int) (Math.random() * 13);
 			tv.setText(strings[idx]);
@@ -123,7 +129,7 @@ class Sync extends AsyncTask<Void, Void, Void> {
 			dialog.dismiss();
 
 			//Check db version again
-			SQLiteDatabase db = myContextRef.openOrCreateDatabase(GM.DB.NAME, Activity.MODE_PRIVATE, null);
+			SQLiteDatabase db = ctx.openOrCreateDatabase(GM.DB.NAME, Activity.MODE_PRIVATE, null);
 			if (db.isReadOnly()){
 				Log.e("SYNC", "Database is in read only mode. Skipping sync.");
 				return;
@@ -186,10 +192,10 @@ class Sync extends AsyncTask<Void, Void, Void> {
 	 * Called when the AsyncTask is created.
 	 * This constructor is intended for syncs on the background.
 	 *
-	 * @param myContextRef The Context of the calling activity.
+	 * @param ctx The Context of the calling activity.
 	 */
-	public Sync(Activity myContextRef){
-		this.myContextRef = myContextRef;
+	public Sync(Activity ctx){
+		this.ctx = ctx;
 	}
 
     /**
@@ -197,11 +203,11 @@ class Sync extends AsyncTask<Void, Void, Void> {
 	 * This constructor is intended for syncs done from the foreground,
 	 * because it shows and hides a spinner (except for the initial one).
      * 
-     * @param myContextRef The Context of the calling activity.
+     * @param ctx The Context of the calling activity.
      * @param pb The progress bar that will be shown while the sync goes on.
      */
-    public Sync(Activity myContextRef, ProgressBar pb, ImageView iv) {
-        this.myContextRef = myContextRef;
+    public Sync(Activity ctx, ProgressBar pb, ImageView iv) {
+        this.ctx = ctx;
         dialog = null;
         pbSync = pb;
 		ivSync = iv;
@@ -213,15 +219,15 @@ class Sync extends AsyncTask<Void, Void, Void> {
      * This constructor is intended to use only in the first sync,
      * from the foreground, because a dialog will block the UI.
      * 
-     * @param myContextRef The Context of the calling activity.
+     * @param ctx The Context of the calling activity.
      * @param d Dialog of the initial sync
      * @param pb The progress bar that will be shown while the sync goes on.
      * @param activity The calling MainActvity
      */
-    public Sync(Activity myContextRef, ProgressBar pb, ImageView iv, Dialog d, MainActivity activity) {
+    public Sync(Activity ctx, ProgressBar pb, ImageView iv, Dialog d, MainActivity activity) {
     	this.dialog = d;
     	this.activity = activity;
-        this.myContextRef = myContextRef;
+        this.ctx = ctx;
         pbSync = pb;
 		ivSync = iv;
         fg = 1;
@@ -233,7 +239,7 @@ class Sync extends AsyncTask<Void, Void, Void> {
      * @param context The Context of the calling activity.
      */
     public Sync(Context context) {
-        this.myContextRef = context;
+        this.ctx = context;
         pbSync = null;
         fg = 0;
     }
@@ -263,14 +269,14 @@ class Sync extends AsyncTask<Void, Void, Void> {
 	 * @return The URL that will be used for syncing.
 	 */
 	private String buildUrl(SQLiteDatabase db, String user, int foreground){
-		String url = "";
+		StringBuilder url = new StringBuilder();
 		try {
 
 			// Common parameters
-			url = GM.API.SERVER + GM.API.SYNC.PATH.COMPLETE + "?" +
-			  GM.API.SYNC.KEY.CLIENT + "=" + URLEncoder.encode(GM.API.CLIENT, "UTF-8") + "&" +
-			  GM.API.SYNC.KEY.USER + "=" + URLEncoder.encode(user, "UTF-8") + "&" +
-			  GM.API.SYNC.KEY.FOREGROUND + "=" + foreground;
+			url = new StringBuilder(GM.API.SERVER + GM.API.SYNC.PATH.COMPLETE + "?" +
+					GM.API.SYNC.KEY.CLIENT + "=" + URLEncoder.encode(GM.API.CLIENT, "UTF-8") + "&" +
+					GM.API.SYNC.KEY.USER + "=" + URLEncoder.encode(user, "UTF-8") + "&" +
+					GM.API.SYNC.KEY.FOREGROUND + "=" + foreground);
 
 			// Versions of the tables
 			Cursor cursor;
@@ -293,7 +299,7 @@ class Sync extends AsyncTask<Void, Void, Void> {
 				List<String> tableList = Arrays.asList(tables);
 				while (cursor.moveToNext()) {
 					if(tableList.contains(cursor.getString(0))){
-						url = url + "&" + cursor.getString(0) + "=" + cursor.getString(1);
+						url.append("&").append(cursor.getString(0)).append("=").append(cursor.getString(1));
 					}
 				}
 			}
@@ -302,7 +308,7 @@ class Sync extends AsyncTask<Void, Void, Void> {
 		catch (java.io.UnsupportedEncodingException ex){
 			Log.e("SYNC", "Error encoding url for sync \"" + url + "\" - " + ex.toString());
 		}
-		return url;
+		return url.toString();
 	}
 
 
@@ -389,7 +395,7 @@ class Sync extends AsyncTask<Void, Void, Void> {
 	 */
 	private boolean saveSettings(String settings){
 
-		SharedPreferences sharedData = myContextRef.getSharedPreferences(GM.DATA.DATA, Context.MODE_PRIVATE);
+		SharedPreferences sharedData = ctx.getSharedPreferences(GM.DATA.DATA, Context.MODE_PRIVATE);
 		SharedPreferences.Editor editor = sharedData.edit();
 		try{
 			String value;
@@ -560,13 +566,13 @@ class Sync extends AsyncTask<Void, Void, Void> {
 				}
 
 				//Start building the query
-				String q = "INSERT INTO " + table + "(";
+				StringBuilder q = new StringBuilder("INSERT INTO " + table + "(");
 
 				//Add column names
 				for (int j = 0; j < i; j++) {
-					q = q + columns[j] + ", ";
+					q.append(columns[j]).append(", ");
 				}
-				q = q.substring(0, q.length() - 2) + ") VALUES (";
+				q = new StringBuilder(q.substring(0, q.length() - 2) + ") VALUES (");
 
 				//Loop trough values
 				for (int j = 0; j < i; j++) {
@@ -574,7 +580,7 @@ class Sync extends AsyncTask<Void, Void, Void> {
 					//If the value is empty or null, I don't care what type is it, it will be 'null'.
 					if (values[j].length() == 0 || "null".equalsIgnoreCase(values[j])) {
 						val = "null";
-						q = q + val + ", ";
+						q.append(val).append(", ");
 					}
 
 					//If the value is not empty, I need the type
@@ -586,29 +592,29 @@ class Sync extends AsyncTask<Void, Void, Void> {
 
 								//Check that is really a number to prevent injection.
 								if (Pattern.matches("-?\\d+", values[j]))
-									q = q + values[j] + ", ";
+									q.append(values[j]).append(", ");
 								else{
 									//If its not and actually number, just insert null to avoid problems.
-									q = q + "null, ";
+									q.append("null, ");
 								}
 								break;
 
 							case GM.DB.COLUMN.DATETIME:
 								//The API formats ('YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS') are good for inserting. Just escape and add quotes.
-								q = q + DatabaseUtils.sqlEscapeString(values[j]) + ", ";
+								q.append(DatabaseUtils.sqlEscapeString(values[j])).append(", ");
 								break;
 
 							default: //VARCHAR
 								//Just escape and add quotes.
-								q = q + DatabaseUtils.sqlEscapeString(values[j]) + ", ";
+								q.append(DatabaseUtils.sqlEscapeString(values[j])).append(", ");
 						}
 					}
 
 				}
 
 				//End the query string and add it to the array.
-				q = q.substring(0, q.length() - 2) + ")";
-				queries.add(q);
+				q = new StringBuilder(q.substring(0, q.length() - 2) + ")");
+				queries.add(q.toString());
 
 			}
 			catch (JSONException e) {
@@ -648,7 +654,7 @@ class Sync extends AsyncTask<Void, Void, Void> {
 	protected Void doInBackground(Void... params) {
 
 		//Get preferences
-		SharedPreferences preferences = myContextRef.getSharedPreferences(GM.DATA.DATA, Context.MODE_PRIVATE);
+		SharedPreferences preferences = ctx.getSharedPreferences(GM.DATA.DATA, Context.MODE_PRIVATE);
 
 		//Get useful data for the uri
 		String userCode = preferences.getString(GM.DATA.KEY.USER, GM.DATA.DEFAULT.USER);
@@ -656,7 +662,7 @@ class Sync extends AsyncTask<Void, Void, Void> {
 		//Get database. Stop if it's locked
 		SQLiteDatabase db;
 		try {
-			db = myContextRef.openOrCreateDatabase(GM.DB.NAME, Activity.MODE_PRIVATE, null);
+			db = ctx.openOrCreateDatabase(GM.DB.NAME, Activity.MODE_PRIVATE, null);
 			if (db.isReadOnly()) {
 				Log.e("SYNC", "Database is in read only mode. Skipping sync.");
 				return null;

+ 4 - 4
app/src/main/java/com/ivalentin/margolariak/UsActivity.java

@@ -51,25 +51,25 @@ public class UsActivity extends Activity {
 		llCuadrilla.setOnClickListener(new View.OnClickListener() {
 			@Override
 			public void onClick(View v) {
-				openDialog(getString(R.string.us_cuadrilla), getString(R.string.us_cuadrilla_content), getResources().getDrawable(R.drawable.us_cuadrilla, null));
+				openDialog(getString(R.string.us_cuadrilla), getString(R.string.us_cuadrilla_content), getResources().getDrawable(R.drawable.us_cuadrilla));
 			}
 		});
 		llAssociation.setOnClickListener(new View.OnClickListener() {
 			@Override
 			public void onClick(View v) {
-				openDialog(getString(R.string.us_association), getString(R.string.us_association_content), getResources().getDrawable(R.drawable.us_asociacion, null));
+				openDialog(getString(R.string.us_association), getString(R.string.us_association_content), getResources().getDrawable(R.drawable.us_asociacion));
 			}
 		});
 		llActivities.setOnClickListener(new View.OnClickListener() {
 			@Override
 			public void onClick(View v) {
-				openDialog(getString(R.string.us_activities), getString(R.string.us_activities_content), getResources().getDrawable(R.drawable.us_activities, null));
+				openDialog(getString(R.string.us_activities), getString(R.string.us_activities_content), getResources().getDrawable(R.drawable.us_activities));
 			}
 		});
 		llTransparency.setOnClickListener(new View.OnClickListener() {
 			@Override
 			public void onClick(View v) {
-				openDialog(getString(R.string.us_transparency), getString(R.string.us_transparency_content), getResources().getDrawable(R.drawable.us_transparency, null));
+				openDialog(getString(R.string.us_transparency), getString(R.string.us_transparency_content), getResources().getDrawable(R.drawable.us_transparency));
 			}
 		});
 

BIN
app/src/main/res/drawable-hdpi/ic_launcher.png


BIN
app/src/main/res/drawable-hdpi/ic_notification.png


BIN
app/src/main/res/drawable-hdpi/social_facebook.png


BIN
app/src/main/res/drawable-hdpi/social_googleplus.png


BIN
app/src/main/res/drawable-hdpi/social_instagram.png


BIN
app/src/main/res/drawable-hdpi/social_mail.png


BIN
app/src/main/res/drawable-hdpi/social_phone.png


BIN
app/src/main/res/drawable-hdpi/social_twitter.png


BIN
app/src/main/res/drawable-hdpi/social_whatsapp.png


BIN
app/src/main/res/drawable-hdpi/social_youtube.png


BIN
app/src/main/res/drawable-hdpi/us_activities.png


BIN
app/src/main/res/drawable-hdpi/us_asociacion.png


BIN
app/src/main/res/drawable-hdpi/us_cuadrilla.png


BIN
app/src/main/res/drawable-hdpi/us_transparency.png


BIN
app/src/main/res/drawable-ldpi/ic_launcher.png


BIN
app/src/main/res/drawable-ldpi/ic_notification.png


BIN
app/src/main/res/drawable-ldpi/social_facebook.png


BIN
app/src/main/res/drawable-ldpi/social_googleplus.png


BIN
app/src/main/res/drawable-ldpi/social_instagram.png


BIN
app/src/main/res/drawable-ldpi/social_mail.png


BIN
app/src/main/res/drawable-ldpi/social_phone.png


BIN
app/src/main/res/drawable-ldpi/social_twitter.png


BIN
app/src/main/res/drawable-ldpi/social_whatsapp.png


BIN
app/src/main/res/drawable-ldpi/social_youtube.png


BIN
app/src/main/res/drawable-ldpi/us_activities.png


BIN
app/src/main/res/drawable-ldpi/us_asociacion.png


BIN
app/src/main/res/drawable-ldpi/us_cuadrilla.png


BIN
app/src/main/res/drawable-ldpi/us_transparency.png


BIN
app/src/main/res/drawable-mdpi/ic_launcher.png


BIN
app/src/main/res/drawable-mdpi/ic_notification.png


BIN
app/src/main/res/drawable-mdpi/social_facebook.png


BIN
app/src/main/res/drawable-mdpi/social_googleplus.png


BIN
app/src/main/res/drawable-mdpi/social_instagram.png


BIN
app/src/main/res/drawable-mdpi/social_mail.png


BIN
app/src/main/res/drawable-mdpi/social_phone.png


BIN
app/src/main/res/drawable-mdpi/social_twitter.png


BIN
app/src/main/res/drawable-mdpi/social_whatsapp.png


BIN
app/src/main/res/drawable-mdpi/social_youtube.png


BIN
app/src/main/res/drawable-mdpi/us_activities.png


BIN
app/src/main/res/drawable-mdpi/us_asociacion.png


BIN
app/src/main/res/drawable-mdpi/us_cuadrilla.png


BIN
app/src/main/res/drawable-mdpi/us_transparency.png


BIN
app/src/main/res/drawable-nodpi/comment.png


BIN
app/src/main/res/drawable-nodpi/photo_placeholder_miniature.png


BIN
app/src/main/res/drawable-nodpi/photo_placeholder_preview.png


BIN
app/src/main/res/drawable-nodpi/photo_placeholder_thumb.png


+ 0 - 0
app/src/main/res/drawable/pinpoint.png → app/src/main/res/drawable-nodpi/pinpoint.png


+ 0 - 0
app/src/main/res/drawable/pinpoint_end.png → app/src/main/res/drawable-nodpi/pinpoint_end.png


+ 0 - 0
app/src/main/res/drawable/pinpoint_route.png → app/src/main/res/drawable-nodpi/pinpoint_route.png


+ 0 - 0
app/src/main/res/drawable/pinpoint_start.png → app/src/main/res/drawable-nodpi/pinpoint_start.png


+ 0 - 0
app/src/main/res/drawable/schedule_point.png → app/src/main/res/drawable-nodpi/schedule_point.png


+ 0 - 0
app/src/main/res/drawable/schedule_timeline.png → app/src/main/res/drawable-nodpi/schedule_timeline.png


+ 0 - 0
app/src/main/res/drawable/ul.png → app/src/main/res/drawable-nodpi/ul.png


BIN
app/src/main/res/drawable-nodpi/web.png


BIN
app/src/main/res/drawable-xhdpi/ic_launcher.png


BIN
app/src/main/res/drawable-xhdpi/ic_notification.png


BIN
app/src/main/res/drawable-xhdpi/social_facebook.png


BIN
app/src/main/res/drawable-xhdpi/social_googleplus.png


BIN
app/src/main/res/drawable-xhdpi/social_instagram.png


BIN
app/src/main/res/drawable-xhdpi/social_mail.png


BIN
app/src/main/res/drawable-xhdpi/social_phone.png


BIN
app/src/main/res/drawable-xhdpi/social_twitter.png


BIN
app/src/main/res/drawable-xhdpi/social_whatsapp.png


BIN
app/src/main/res/drawable-xhdpi/social_youtube.png


BIN
app/src/main/res/drawable-xhdpi/us_activities.png


BIN
app/src/main/res/drawable-xhdpi/us_asociacion.png


BIN
app/src/main/res/drawable-xhdpi/us_cuadrilla.png


BIN
app/src/main/res/drawable-xhdpi/us_transparency.png


BIN
app/src/main/res/drawable-xxhdpi/ic_launcher.png


BIN
app/src/main/res/drawable-xxhdpi/ic_notification.png


BIN
app/src/main/res/drawable-xxhdpi/social_facebook.png


BIN
app/src/main/res/drawable-xxhdpi/social_googleplus.png


BIN
app/src/main/res/drawable-xxhdpi/social_instagram.png


BIN
app/src/main/res/drawable-xxhdpi/social_mail.png


BIN
app/src/main/res/drawable-xxhdpi/social_phone.png


BIN
app/src/main/res/drawable-xxhdpi/social_twitter.png


BIN
app/src/main/res/drawable-xxhdpi/social_whatsapp.png


BIN
app/src/main/res/drawable-xxhdpi/social_youtube.png


BIN
app/src/main/res/drawable-xxhdpi/us_activities.png


BIN
app/src/main/res/drawable-xxhdpi/us_asociacion.png


BIN
app/src/main/res/drawable-xxhdpi/us_cuadrilla.png


BIN
app/src/main/res/drawable-xxhdpi/us_transparency.png


BIN
app/src/main/res/drawable-xxxhdpi/ic_launcher.png


BIN
app/src/main/res/drawable-xxxhdpi/ic_notification.png


BIN
app/src/main/res/drawable-xxxhdpi/social_facebook.png


Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff