From 9acfb96f4e73d54e7d450bbead6924bffa8dfb20 Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Tue, 25 Jul 2017 13:18:19 +0200 Subject: [PATCH 01/38] new play services version --- nearit/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nearit/build.gradle b/nearit/build.gradle index e04f0a01..3583f92b 100644 --- a/nearit/build.gradle +++ b/nearit/build.gradle @@ -64,7 +64,7 @@ def getLatestVersionName = { } } -def playServicesVersion = '10.2.0' +def playServicesVersion = '11.0.2' allprojects{ version = "${getVersionName()}" From 15f8157e121e015afb20a10e5b1c1aeb63ab1bb1 Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Tue, 25 Jul 2017 13:18:50 +0200 Subject: [PATCH 02/38] using new entry points for location ping and geofence add/remove --- .../geopolis/geofences/GeoFenceService.java | 53 ++++++++++++++----- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java b/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java index d5137237..b2f4a3df 100644 --- a/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java +++ b/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java @@ -7,24 +7,23 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; -import android.location.Criteria; import android.location.Location; -import android.location.LocationListener; -import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.ActivityCompat; - import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.ResultCallback; import com.google.android.gms.common.api.Status; +import com.google.android.gms.location.FusedLocationProviderClient; import com.google.android.gms.location.Geofence; +import com.google.android.gms.location.GeofencingClient; import com.google.android.gms.location.GeofencingRequest; import com.google.android.gms.location.LocationServices; +import com.google.android.gms.tasks.OnSuccessListener; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; @@ -49,11 +48,15 @@ public class GeoFenceService extends Service implements GoogleApiClient.Connecti private GoogleApiClient mGoogleApiClient; private List mNearGeoList; private List mPendingGeofences = new ArrayList<>(); + private FusedLocationProviderClient fusedLocationProviderClient; + private GeofencingClient geofencingClient; @Override public void onCreate() { super.onCreate(); NearLog.d(TAG, "onCreate()"); + fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this); + geofencingClient = LocationServices.getGeofencingClient(this); } @Override @@ -77,7 +80,22 @@ public int onStartCommand(Intent intent, int flags, int startId) { } private void pingSingleLocation() { - LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); + if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && + ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + return; + } + fusedLocationProviderClient.getLastLocation() + .addOnSuccessListener(new OnSuccessListener() { + @Override + public void onSuccess(Location location) { + if (location != null) { + NearLog.d(TAG, "onLocationChanged"); + NearLog.d(TAG, "location: " + location.getLongitude() + " " + location.getLatitude()); + } + } + }); + + /*LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); criteria.setPowerRequirement(Criteria.POWER_LOW); @@ -112,7 +130,7 @@ public void onProviderEnabled(String s) { public void onProviderDisabled(String s) { NearLog.d(TAG, "onProviderDisabled"); } - }, null); + }, null);*/ } @Override @@ -135,9 +153,9 @@ public IBinder onBind(Intent intent) { */ private void startGoogleApiClient() { mGoogleApiClient = new GoogleApiClient.Builder(this) + .addApi(LocationServices.API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) - .addApi(LocationServices.API) .build(); mGoogleApiClient.connect(); } @@ -259,8 +277,13 @@ public void stopGeofencing(List idsToremove) { if (idsToremove == null || idsToremove.size() == 0) return; if (mGoogleApiClient == null || !mGoogleApiClient.isConnected()) return; - LocationServices.GeofencingApi.removeGeofences(mGoogleApiClient, idsToremove) - .setResultCallback(this); + geofencingClient.removeGeofences(idsToremove) + .addOnSuccessListener(new OnSuccessListener() { + @Override + public void onSuccess(Void aVoid) { + NearLog.d(TAG, "Geofences removed"); + } + }); } /** @@ -287,12 +310,16 @@ private void startGeoFencing(GeofencingRequest request) { return; } NearLog.d(TAG, "startGeofencing"); - LocationServices.GeofencingApi.addGeofences( - mGoogleApiClient, + geofencingClient.addGeofences( request, getGeofencePendingIntent() - ).setResultCallback(this); - pingSingleLocation(); + ).addOnSuccessListener(new OnSuccessListener() { + @Override + public void onSuccess(Void aVoid) { + NearLog.d(TAG, "Geofences added"); + pingSingleLocation(); + } + }); } From 974ebdfedc8d1c8da9baf9244ccce07dad12c7c7 Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Tue, 25 Jul 2017 13:21:43 +0200 Subject: [PATCH 03/38] todo --- .../it/near/sdk/geopolis/geofences/GeoFenceService.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java b/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java index b2f4a3df..f997613e 100644 --- a/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java +++ b/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java @@ -162,21 +162,18 @@ private void startGoogleApiClient() { /** * Load geofence request ids from disk. - * - * @return */ private List loadIds() { Gson gson = new Gson(); SharedPreferences sp = getSharedPreferences(getSharedPrefName(this), 0); String jsonText = sp.getString(LIST_IDS, null); + // TODO not catching the unchecked exception is dangerous return gson.fromJson(jsonText, new TypeToken>() { }.getType()); } /** * Overwrite geofence request ids. - * - * @param ids */ private void saveIds(List ids) { Gson gson = new Gson(); @@ -186,8 +183,6 @@ private void saveIds(List ids) { /** * Reset the listened geofence request ids. - * - * @param context */ public static void resetIds(Context context) { SharedPreferences.Editor edit = context.getSharedPreferences(getSharedPrefName(context), 0).edit(); From be7a8e7e3a920e23f1516ab5cb2804b277a04430 Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Tue, 25 Jul 2017 17:12:12 +0200 Subject: [PATCH 04/38] will this break CI? --- sample/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sample/build.gradle b/sample/build.gradle index 3cf78d1d..65731e15 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -24,7 +24,7 @@ android { config { } } - compileSdkVersion 25 + compileSdkVersion 26 buildToolsVersion '25.0.2' defaultConfig { applicationId "com.nearit.sample" @@ -55,7 +55,7 @@ dependencies { exclude group: 'com.android.support', module: 'support-annotations' }) - // compile 'it.near.sdk:nearit:2.1.30' + // compile 'it.near.sdk:nearit:2.1.32' compile project(':nearit') compile 'com.android.support:appcompat-v7:24.2.1' From 681ff574aff883f372f0476707fbd5933adcbdfa Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Tue, 25 Jul 2017 17:35:52 +0200 Subject: [PATCH 05/38] revert compile and target sdk api level for sample --- sample/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sample/build.gradle b/sample/build.gradle index 65731e15..056cba42 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -24,12 +24,12 @@ android { config { } } - compileSdkVersion 26 + compileSdkVersion 25 buildToolsVersion '25.0.2' defaultConfig { applicationId "com.nearit.sample" minSdkVersion 15 - targetSdkVersion 26 + targetSdkVersion 25 versionCode 1 versionName "1.0" From 8bcdd09b52169f061ae90e9e96e99452cfd097f7 Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Wed, 26 Jul 2017 10:22:51 +0200 Subject: [PATCH 06/38] ping --- .../java/it/near/sdk/geopolis/geofences/GeoFenceService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java b/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java index f997613e..89f2674a 100644 --- a/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java +++ b/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java @@ -41,12 +41,10 @@ public class GeoFenceService extends Service implements GoogleApiClient.Connecti private static final String TAG = "GeoFenceService"; private static final String PREF_SUFFIX = "NearGeo"; - private static final String GEO_LIST = "GeofenceList"; private static final String LIST_IDS = "list_ids"; public static final String GEOFENCES = "geofences"; private PendingIntent mGeofencePendingIntent; private GoogleApiClient mGoogleApiClient; - private List mNearGeoList; private List mPendingGeofences = new ArrayList<>(); private FusedLocationProviderClient fusedLocationProviderClient; private GeofencingClient geofencingClient; @@ -315,6 +313,8 @@ public void onSuccess(Void aVoid) { pingSingleLocation(); } }); + // TODO maybe remove this + pingSingleLocation(); } From b9af88cb3d1e8bdbb481215e8847d766eb7b89fc Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Mon, 31 Jul 2017 15:28:42 +0200 Subject: [PATCH 07/38] add utils for fetching itef bcp 47 on API < 21 --- .../java/it/near/sdk/utils/NearUtils.java | 77 +++++++++++++++++-- 1 file changed, 71 insertions(+), 6 deletions(-) diff --git a/nearit/src/main/java/it/near/sdk/utils/NearUtils.java b/nearit/src/main/java/it/near/sdk/utils/NearUtils.java index fba91ced..e05a0747 100644 --- a/nearit/src/main/java/it/near/sdk/utils/NearUtils.java +++ b/nearit/src/main/java/it/near/sdk/utils/NearUtils.java @@ -1,6 +1,7 @@ package it.near.sdk.utils; import android.content.Intent; +import android.os.Build; import android.os.Parcelable; import android.util.Base64; @@ -8,19 +9,19 @@ import java.io.UnsupportedEncodingException; import java.util.Collections; +import java.util.Locale; import it.near.sdk.logging.NearLog; -import it.near.sdk.reactions.contentplugin.model.Content; import it.near.sdk.reactions.contentplugin.ContentReaction; -import it.near.sdk.reactions.couponplugin.model.Coupon; +import it.near.sdk.reactions.contentplugin.model.Content; import it.near.sdk.reactions.couponplugin.CouponReaction; -import it.near.sdk.reactions.customjsonplugin.model.CustomJSON; +import it.near.sdk.reactions.couponplugin.model.Coupon; import it.near.sdk.reactions.customjsonplugin.CustomJSONReaction; -import it.near.sdk.reactions.feedbackplugin.model.Feedback; +import it.near.sdk.reactions.customjsonplugin.model.CustomJSON; import it.near.sdk.reactions.feedbackplugin.FeedbackReaction; - -import it.near.sdk.reactions.simplenotificationplugin.model.SimpleNotification; +import it.near.sdk.reactions.feedbackplugin.model.Feedback; import it.near.sdk.reactions.simplenotificationplugin.SimpleNotificationReaction; +import it.near.sdk.reactions.simplenotificationplugin.model.SimpleNotification; import it.near.sdk.recipes.models.Recipe; public class NearUtils { @@ -75,6 +76,70 @@ private static String substringBetween(String str, String open, String close) { return null; } + /** + * Taken from: + * https://stackoverflow.com/questions/29657781/how-to-i-get-the-ietf-bcp47-language-code-in-android-api-21 + * + * Modified from: + * https://github.com/apache/cordova-plugin-globalization/blob/master/src/android/Globalization.java + * + * Returns a well-formed ITEF BCP 47 language tag representing this locale string + * identifier for the client's current locale + * + * @return String: The BCP 47 language tag for the current locale + */ + public static String toBcp47Language(Locale loc) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + return loc.toLanguageTag(); + } + + // we will use a dash as per BCP 47 + final char SEP = '-'; + String language = loc.getLanguage(); + String region = loc.getCountry(); + String variant = loc.getVariant(); + + // special case for Norwegian Nynorsk since "NY" cannot be a variant as per BCP 47 + // this goes before the string matching since "NY" wont pass the variant checks + if (language.equals("no") && region.equals("NO") && variant.equals("NY")) { + language = "nn"; + region = "NO"; + variant = ""; + } + + if (language.isEmpty() || !language.matches("\\p{Alpha}{2,8}")) { + language = "und"; // Follow the Locale#toLanguageTag() implementation + // which says to return "und" for Undetermined + } else if (language.equals("iw")) { + language = "he"; // correct deprecated "Hebrew" + } else if (language.equals("in")) { + language = "id"; // correct deprecated "Indonesian" + } else if (language.equals("ji")) { + language = "yi"; // correct deprecated "Yiddish" + } + + // ensure valid country code, if not well formed, it's omitted + if (!region.matches("\\p{Alpha}{2}|\\p{Digit}{3}")) { + region = ""; + } + + // variant subtags that begin with a letter must be at least 5 characters long + if (!variant.matches("\\p{Alnum}{5,8}|\\p{Digit}\\p{Alnum}{3}")) { + variant = ""; + } + + StringBuilder bcp47Tag = new StringBuilder(language); + if (!region.isEmpty()) { + bcp47Tag.append(SEP).append(region); + } + if (!variant.isEmpty()) { + bcp47Tag.append(SEP).append(variant); + } + + return bcp47Tag.toString(); + } + + /** * Utility method for automatically casting content. It notifies the listener if the intent contains a recognized core content. * From d286fafbf56a3718ba758efbecc31db38e143fe7 Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Mon, 31 Jul 2017 15:29:09 +0200 Subject: [PATCH 08/38] add lang in installation data --- .../java/it/near/sdk/communication/NearInstallation.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nearit/src/main/java/it/near/sdk/communication/NearInstallation.java b/nearit/src/main/java/it/near/sdk/communication/NearInstallation.java index a6dbb0d1..9e2a9d08 100644 --- a/nearit/src/main/java/it/near/sdk/communication/NearInstallation.java +++ b/nearit/src/main/java/it/near/sdk/communication/NearInstallation.java @@ -12,10 +12,12 @@ import org.json.JSONException; import java.util.HashMap; +import java.util.Locale; import it.near.sdk.GlobalConfig; import it.near.sdk.logging.NearLog; import it.near.sdk.utils.NearJsonAPIUtils; +import it.near.sdk.utils.NearUtils; /** * Class with static method to register an app installation to our Near APIs. @@ -35,6 +37,7 @@ public class NearInstallation { private static final String LOCATION = "location"; private static final String TAG = "NearInstallation"; private static final String PROFILE_ID = "profile_id"; + private static final String LANG = "lang"; private NearInstallationRequestQueue requestQueue; private Context context; @@ -84,9 +87,15 @@ private String getInstallationBody(Context context, GlobalConfig globalConfig, S attributeMap.put(BLUETOOTH, getBluetoothStatus()); // Set location permission attributeMap.put(LOCATION, getLocationPermissionStatus(context)); + // Set language + attributeMap.put(LANG, getDeviceLanguage()); return NearJsonAPIUtils.toJsonAPI(INSTALLATION_RES_TYPE, id, attributeMap); } + private String getDeviceLanguage() { + return NearUtils.toBcp47Language(Locale.getDefault()); + } + private static boolean getLocationPermissionStatus(Context context) { return ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED; From 73b18c4a85a4d26249057bbd1248d35555ce5c1c Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Mon, 31 Jul 2017 15:29:59 +0200 Subject: [PATCH 09/38] add lang in evaluation core object --- .../main/java/it/near/sdk/recipes/EvaluationBodyBuilder.java | 3 +++ .../java/it/near/sdk/recipes/EvaluationBodyBuilderTest.java | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/nearit/src/main/java/it/near/sdk/recipes/EvaluationBodyBuilder.java b/nearit/src/main/java/it/near/sdk/recipes/EvaluationBodyBuilder.java index e0f890b9..686bd92e 100644 --- a/nearit/src/main/java/it/near/sdk/recipes/EvaluationBodyBuilder.java +++ b/nearit/src/main/java/it/near/sdk/recipes/EvaluationBodyBuilder.java @@ -11,6 +11,7 @@ import it.near.sdk.GlobalConfig; import it.near.sdk.utils.CurrentTime; import it.near.sdk.utils.NearJsonAPIUtils; +import it.near.sdk.utils.NearUtils; import static it.near.sdk.utils.NearUtils.checkNotNull; @@ -25,6 +26,7 @@ public class EvaluationBodyBuilder { static final String KEY_INSTALLATION_ID = "installation_id"; static final String KEY_APP_ID = "app_id"; static final String KEY_UTC_OFFSET = "utc_offset"; + static final String KEY_LANG = "lang"; static final String KEY_COOLDOWN = "cooldown"; static final String KEY_LAST_NOTIFIED_AT = "last_notified_at"; static final String KEY_RECIPES_NOTIFIED_AT = "recipes_notified_at"; @@ -66,6 +68,7 @@ private HashMap buildCoreObject() { coreObj.put(KEY_INSTALLATION_ID, globalConfig.getInstallationId()); coreObj.put(KEY_APP_ID, globalConfig.getAppId()); coreObj.put(KEY_UTC_OFFSET, buildUtcOffset()); + coreObj.put(KEY_LANG, NearUtils.toBcp47Language(Locale.getDefault())); if (recipesHistory != null) { coreObj.put(KEY_COOLDOWN, buildCooldownBlock()); } diff --git a/nearit/src/test/java/it/near/sdk/recipes/EvaluationBodyBuilderTest.java b/nearit/src/test/java/it/near/sdk/recipes/EvaluationBodyBuilderTest.java index 973e2806..7a27dcdf 100644 --- a/nearit/src/test/java/it/near/sdk/recipes/EvaluationBodyBuilderTest.java +++ b/nearit/src/test/java/it/near/sdk/recipes/EvaluationBodyBuilderTest.java @@ -11,6 +11,7 @@ import org.mockito.junit.MockitoJUnitRunner; import java.util.Calendar; +import java.util.Locale; import java.util.Map; import java.util.TimeZone; @@ -21,6 +22,7 @@ import static it.near.sdk.recipes.EvaluationBodyBuilder.KEY_COOLDOWN; import static it.near.sdk.recipes.EvaluationBodyBuilder.KEY_CORE; import static it.near.sdk.recipes.EvaluationBodyBuilder.KEY_INSTALLATION_ID; +import static it.near.sdk.recipes.EvaluationBodyBuilder.KEY_LANG; import static it.near.sdk.recipes.EvaluationBodyBuilder.KEY_LAST_NOTIFIED_AT; import static it.near.sdk.recipes.EvaluationBodyBuilder.KEY_PROFILE_ID; import static it.near.sdk.recipes.EvaluationBodyBuilder.KEY_RECIPES_NOTIFIED_AT; @@ -55,6 +57,7 @@ public void setUp() { when(mockGlobalConfig.getInstallationId()).thenReturn(MOCKED_INSTALLATION_ID); when(mockGlobalConfig.getProfileId()).thenReturn(MOCKED_PROFILE_ID); when(mockCurrentTime.currentCalendar()).thenReturn(Calendar.getInstance(TimeZone.getTimeZone("GMT+5:30"))); + Locale.setDefault(new Locale("es", "ES")); evaluationBodyBuilder = new EvaluationBodyBuilder(mockGlobalConfig, mockRecipeHistory, mockCurrentTime); } @@ -72,6 +75,7 @@ public void buildCorrectEvaluationBody_noCooldownNoPulse() throws JSONException assertThat((String) actualObj.get(KEY_INSTALLATION_ID), is(MOCKED_INSTALLATION_ID)); assertThat((String) actualObj.get(KEY_APP_ID), is(MOCKED_APP_ID)); assertThat((String) actualObj.get(KEY_UTC_OFFSET), is("+05:30")); + assertThat((String) actualObj.get(KEY_LANG), is("es-ES")); assertThat(actualObj = actualObj.getJSONObject(KEY_COOLDOWN), is(notNullValue())); assertThat(Long.valueOf((Integer) actualObj.get(KEY_LAST_NOTIFIED_AT)), is(0L)); assertThat(actualObj.getJSONObject(KEY_RECIPES_NOTIFIED_AT).length(), is(0)); From c868629c7999c42da1fabe98769842e9c6b3f0e0 Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Thu, 3 Aug 2017 14:33:52 +0200 Subject: [PATCH 10/38] add accept language as header --- .../src/main/java/it/near/sdk/communication/Constants.java | 2 ++ .../java/it/near/sdk/communication/NearAsyncHttpClient.java | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/nearit/src/main/java/it/near/sdk/communication/Constants.java b/nearit/src/main/java/it/near/sdk/communication/Constants.java index 773d7738..1eeab0f9 100644 --- a/nearit/src/main/java/it/near/sdk/communication/Constants.java +++ b/nearit/src/main/java/it/near/sdk/communication/Constants.java @@ -32,6 +32,8 @@ interface Headers { String version_header_key = "X-API-Version"; String near_version_header_key = "X-Near-Version"; + + String acceptLanguage = "Accept-Language"; } // -------------------- PATHS -------------------------- diff --git a/nearit/src/main/java/it/near/sdk/communication/NearAsyncHttpClient.java b/nearit/src/main/java/it/near/sdk/communication/NearAsyncHttpClient.java index a7c53664..e44712bf 100644 --- a/nearit/src/main/java/it/near/sdk/communication/NearAsyncHttpClient.java +++ b/nearit/src/main/java/it/near/sdk/communication/NearAsyncHttpClient.java @@ -12,6 +12,7 @@ import org.json.JSONObject; import java.io.UnsupportedEncodingException; +import java.util.Locale; import cz.msebera.android.httpclient.Header; import cz.msebera.android.httpclient.HttpEntity; @@ -20,6 +21,7 @@ import cz.msebera.android.httpclient.message.BasicHeader; import it.near.sdk.R; import it.near.sdk.utils.ApiKeyConfig; +import it.near.sdk.utils.NearUtils; /** * @author cattaneostefano. @@ -105,7 +107,8 @@ private static Header[] getHeaders(Context context) throws AuthenticationExcepti new BasicHeader(Constants.Headers.contentType, Constants.Headers.jsonApiHeader), new BasicHeader(Constants.Headers.accept, Constants.Headers.jsonApiHeader), new BasicHeader(Constants.Headers.version_header_key, String.valueOf(it.near.sdk.BuildConfig.API_VERSION)), - new BasicHeader(Constants.Headers.near_version_header_key, String.valueOf(it.near.sdk.BuildConfig.NEAR_API_VERSION)) + new BasicHeader(Constants.Headers.near_version_header_key, String.valueOf(it.near.sdk.BuildConfig.NEAR_API_VERSION)), + new BasicHeader(Constants.Headers.acceptLanguage, NearUtils.toBcp47Language(Locale.getDefault())) }; } From 65b36f6773429b37f8eba839d9e088c175bbbffe Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Thu, 31 Aug 2017 15:02:38 +0200 Subject: [PATCH 11/38] little cleanup --- .../java/it/near/sdk/geopolis/geofences/GeoFenceService.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java b/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java index 9888729c..f1c36658 100644 --- a/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java +++ b/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java @@ -45,7 +45,6 @@ public class GeoFenceService extends Service implements GoogleApiClient.Connecti public static final String GEOFENCES = "geofences"; private PendingIntent mGeofencePendingIntent; private GoogleApiClient mGoogleApiClient; - private List mNearGeoList; private List mPendingGeofences = new ArrayList<>(); private FusedLocationProviderClient fusedLocationProviderClient; private GeofencingClient geofencingClient; @@ -314,8 +313,6 @@ public void onSuccess(Void aVoid) { pingSingleLocation(); } }); - // TODO maybe remove this - pingSingleLocation(); } From b1f8485679ac8bb20061281c2886742d4c5bae6a Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Thu, 31 Aug 2017 15:21:26 +0200 Subject: [PATCH 12/38] remove some logs in altbeacon monitor --- .../geopolis/beacons/AltBeaconMonitor.java | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/nearit/src/main/java/it/near/sdk/geopolis/beacons/AltBeaconMonitor.java b/nearit/src/main/java/it/near/sdk/geopolis/beacons/AltBeaconMonitor.java index 2193f5c1..29788319 100644 --- a/nearit/src/main/java/it/near/sdk/geopolis/beacons/AltBeaconMonitor.java +++ b/nearit/src/main/java/it/near/sdk/geopolis/beacons/AltBeaconMonitor.java @@ -60,7 +60,6 @@ public class AltBeaconMonitor extends OnLifecycleEventListener implements Beacon private Map rangingRadars; public AltBeaconMonitor(Context context, NodesManager nodesManager) { - NearLog.d(TAG, "Altbeacon started"); this.context = context; this.nodesManager = nodesManager; this.rangingRadars = new HashMap<>(); @@ -266,7 +265,6 @@ private void resetMonitoring() { } public void onForeground() { - NearLog.d(TAG, "onForeground"); // When going to the foreground, if we have regions to range, start ranging refreshRangingList(); @@ -275,14 +273,12 @@ public void onForeground() { private void refreshRangingList() { if (loadRegions() == null) return; - NearLog.d(TAG, "refreshranging list on: " + loadRegions().size()); for (Region region : loadRegions()) { beaconManager.requestStateForRegion(region); } } public void onBackground() { - NearLog.d(TAG, "onBackground"); // Console.clear(); // When going to the background stop ranging, in an idempotent way (we might haven't been ranging) stopRanging(); @@ -296,13 +292,12 @@ public void didEnterRegion(Region region) { String msg = "enter region: " + region.toString(); NearLog.d(TAG, msg); - logRangedRegions(); // nearit trigger notifyEventOnBeaconRegion(region, GeopolisManager.BT_ENTRY_ACTION_SUFFIX); } private void notifyEventOnBeaconRegion(Region region, String eventActionSuffix) { - NearLog.d(TAG, "Region event: " + eventActionSuffix + " on region: " + region.toString()); + // NearLog.d(TAG, "Region event: " + eventActionSuffix + " on region: " + region.toString()); Intent intent = new Intent(); String packageName = context.getPackageName(); intent.setAction(packageName + "." + eventActionSuffix); @@ -315,7 +310,6 @@ public void didExitRegion(Region region) { String msg = "exit region: " + region.toString(); NearLog.d(TAG, msg); - logRangedRegions(); notifyEventOnBeaconRegion(region, GeopolisManager.BT_EXIT_ACTION_SUFFIX); if (beaconManager.getRangedRegions().size() == 0) { // if the list of ranged regions is empty, we stop ranging @@ -330,7 +324,7 @@ public void didDetermineStateForRegion(int i, Region region) { // so we don't want to trigger and track a recipe here, but we still handle the region ranging in this callback. // basically, idempotent logic lives here - NearLog.d(TAG, "determine state " + i + " for region: " + region.toString()); + // NearLog.d(TAG, "determine state " + i + " for region: " + region.toString()); try { if (i == MonitorNotifier.INSIDE) { @@ -352,12 +346,9 @@ public void didDetermineStateForRegion(int i, Region region) { } } catch (RemoteException e) { } - NearLog.d(TAG, "regions ranged: " + beaconManager.getRangedRegions().size()); - logRangedRegions(); - + // NearLog.d(TAG, "regions ranged: " + beaconManager.getRangedRegions().size()); } - private void startRangingRegion(Region region) throws RemoteException { // we force the foreground mode, to avoid the phone not ranging after a swipe inside an area beaconManager.setBackgroundMode(false); @@ -399,11 +390,6 @@ public void didRangeBeaconsInRegion(Collection collection, Region region } - private void logRangedRegions() { - String msg1 = "regions ranged: " + beaconManager.getRangedRegions().size(); - NearLog.d(TAG, msg1); - } - @Override public void onAppGotoForeground() { onForeground(); From fcb09de6babd07481bc0c8dd6f713ca39a78cce1 Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Thu, 31 Aug 2017 15:55:43 +0200 Subject: [PATCH 13/38] remove some logs from recipe repository and api, and change level --- .../main/java/it/near/sdk/recipes/RecipeRepository.java | 2 +- nearit/src/main/java/it/near/sdk/recipes/RecipesApi.java | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/nearit/src/main/java/it/near/sdk/recipes/RecipeRepository.java b/nearit/src/main/java/it/near/sdk/recipes/RecipeRepository.java index c30dd719..b573c7d2 100644 --- a/nearit/src/main/java/it/near/sdk/recipes/RecipeRepository.java +++ b/nearit/src/main/java/it/near/sdk/recipes/RecipeRepository.java @@ -76,7 +76,7 @@ public void syncNeeded() { @Override public void syncNotNeeded() { - NearLog.d(TAG, "Local recipes were up to date, we avoided a process request"); + NearLog.i(TAG, "Local recipes were up to date, we avoided a process request"); listener.onGotRecipes(getLocalRecipes(), getOnlineEv(), false); } }); diff --git a/nearit/src/main/java/it/near/sdk/recipes/RecipesApi.java b/nearit/src/main/java/it/near/sdk/recipes/RecipesApi.java index e1618393..ab7a371f 100644 --- a/nearit/src/main/java/it/near/sdk/recipes/RecipesApi.java +++ b/nearit/src/main/java/it/near/sdk/recipes/RecipesApi.java @@ -123,7 +123,6 @@ void evaluateRecipe(String recipeId, final SingleRecipeListener listener) { try { evaluateBody = evaluationBodyBuilder.buildEvaluateBody(); } catch (JSONException e) { - NearLog.d(TAG, "body build error"); listener.onRecipeFetchError("body build error"); return; } @@ -146,12 +145,10 @@ public void onSuccess(int statusCode, Header[] headers, JSONObject response) { @Override public void onFailureUnique(int statusCode, Header[] headers, Throwable throwable, String responseString) { - NearLog.d(TAG, "Error in handling on failure: " + statusCode); listener.onRecipeFetchError("Server error"); } }); } catch (AuthenticationException | UnsupportedEncodingException e) { - NearLog.d(TAG, "Error"); listener.onRecipeFetchError("Error"); } @@ -164,7 +161,6 @@ void onlinePulseEvaluation(String pulse_plugin, String pulse_action, String puls try { evaluateBody = evaluationBodyBuilder.buildEvaluateBody(pulse_plugin, pulse_action, pulse_bundle); } catch (JSONException e) { - NearLog.d(TAG, "body build error"); listener.onRecipeFetchError("can't build evaluation body"); return; } @@ -183,18 +179,14 @@ public void onSuccess(int statusCode, Header[] headers, JSONObject response) { @Override public void onFailureUnique(int statusCode, Header[] headers, Throwable throwable, String responseString) { - NearLog.d(TAG, "Error in handling on failure: " + statusCode); listener.onRecipeFetchError("Server error"); } }); } catch (AuthenticationException e) { - NearLog.d(TAG, "Authentication error"); listener.onRecipeFetchError("Authentication error"); } catch (UnsupportedEncodingException e) { NearLog.d(TAG, "Unsupported encoding"); - listener.onRecipeFetchError("Unsupported encoding"); } catch (NullPointerException e) { - NearLog.d(TAG, "Shouldn't be here"); listener.onRecipeFetchError("Shouldn't be here"); } } From ec14305643f54025b8d8b05b6105af245d98b82e Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Thu, 31 Aug 2017 16:14:30 +0200 Subject: [PATCH 14/38] less documentation boilerplate --- README.md | 8 -------- docs/index.md | 7 ------- 2 files changed, 15 deletions(-) diff --git a/README.md b/README.md index 92ef5b8c..fc01da53 100644 --- a/README.md +++ b/README.md @@ -21,13 +21,6 @@ Once the settings are configured, **everyone** - even people without technical s **NearIT SDK** synchronize with servers and behave accordingly to the settings and the recipes. Any content will be delivered at the right time, you just need to handle its presentation. -## Features -* User Segmentation -* Beacon monitoring and ranging -* Geofence monitoring -* Notifications and in-app content -* Analytics - ## Installation Minimum Requirements: @@ -55,7 +48,6 @@ In your app, you can access the NearItManager instance with NearItManager.getInstance() ``` - ## Integration guide For information on how to integrate all NearIT feautures in your app, visit the [documentation website](http://nearit-android.readthedocs.io/en/latest/?badge=latest) diff --git a/docs/index.md b/docs/index.md index 7cfe274b..9a405ed4 100644 --- a/docs/index.md +++ b/docs/index.md @@ -20,10 +20,3 @@ NearIT allows to manage apps by defining "recipes". Those are simple rules made Once the settings are configured, **everyone** - even people without technical skills - can manage context-aware mobile content. **NearIT SDK** synchronizes with servers and behaves accordingly to the settings and the recipes. Any content will be delivered at the right time, you just need to handle its presentation. - -## Features -* User Segmentation -* Beacon monitoring and ranging -* Geofence monitoring -* Notifications and in-app content -* Analytics From 918887eb360c8f6ec1a2589ca23a23c2803912f8 Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Thu, 31 Aug 2017 17:17:10 +0200 Subject: [PATCH 15/38] change log level --- .../geopolis/geofences/GeoFenceService.java | 53 +++---------------- 1 file changed, 7 insertions(+), 46 deletions(-) diff --git a/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java b/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java index f1c36658..e07f5833 100644 --- a/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java +++ b/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java @@ -52,7 +52,7 @@ public class GeoFenceService extends Service implements GoogleApiClient.Connecti @Override public void onCreate() { super.onCreate(); - NearLog.d(TAG, "onCreate()"); + NearLog.i(TAG, "onCreate()"); fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this); geofencingClient = LocationServices.getGeofencingClient(this); } @@ -60,7 +60,7 @@ public void onCreate() { @Override public int onStartCommand(Intent intent, int flags, int startId) { // can be called multiple times - NearLog.d(TAG, "onStartCommand()"); + NearLog.i(TAG, "onStartCommand()"); if (mGoogleApiClient == null || !mGoogleApiClient.isConnected()) { startGoogleApiClient(); } @@ -87,53 +87,15 @@ private void pingSingleLocation() { @Override public void onSuccess(Location location) { if (location != null) { - NearLog.d(TAG, "onLocationChanged"); - NearLog.d(TAG, "location: " + location.getLongitude() + " " + location.getLatitude()); + NearLog.i(TAG, "location: " + location.getLongitude() + " " + location.getLatitude()); } } }); - - /*LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); - Criteria criteria = new Criteria(); - criteria.setAccuracy(Criteria.ACCURACY_COARSE); - criteria.setPowerRequirement(Criteria.POWER_LOW); - if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { - // TODO: Consider calling - // ActivityCompat#requestPermissions - // here to request the missing permissions, and then overriding - // public void onRequestPermissionsResult(int requestCode, String[] permissions, - // int[] grantResults) - // to handle the case where the user grants the permission. See the documentation - // for ActivityCompat#requestPermissions for more details. - return; - } - locationManager.requestSingleUpdate(criteria, new LocationListener() { - @Override - public void onLocationChanged(Location location) { - NearLog.d(TAG, "onLocationChanged"); - NearLog.d(TAG, "location: " + location.getLongitude() + " " + location.getLatitude()); - } - - @Override - public void onStatusChanged(String s, int i, Bundle bundle) { - NearLog.d(TAG, "onStatusChanged"); - } - - @Override - public void onProviderEnabled(String s) { - NearLog.d(TAG, "onProviderEnabled"); - } - - @Override - public void onProviderDisabled(String s) { - NearLog.d(TAG, "onProviderDisabled"); - } - }, null);*/ } @Override public void onDestroy() { - NearLog.d(TAG, "onDestroy on geofence service"); + NearLog.i(TAG, "onDestroy on geofence service"); super.onDestroy(); stopAllGeofences(); resetIds(this); @@ -274,7 +236,7 @@ public void stopGeofencing(List idsToremove) { .addOnSuccessListener(new OnSuccessListener() { @Override public void onSuccess(Void aVoid) { - NearLog.d(TAG, "Geofences removed"); + NearLog.i(TAG, "Geofences removed"); } }); } @@ -309,7 +271,6 @@ private void startGeoFencing(GeofencingRequest request) { ).addOnSuccessListener(new OnSuccessListener() { @Override public void onSuccess(Void aVoid) { - NearLog.d(TAG, "Geofences added"); pingSingleLocation(); } }); @@ -367,12 +328,12 @@ public void onConnectionSuspended(int i) { @Override public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { - NearLog.d(TAG, "onConnectionFailed"); + NearLog.i(TAG, "onConnectionFailed"); } @Override public void onResult(@NonNull Status status) { - NearLog.d(TAG, "onResult: " + status.getStatusMessage()); + NearLog.i(TAG, "onResult: " + status.getStatusMessage()); } public static String getSharedPrefName(Context context) { From b04bfd11088e3fe7b0f1b71c3948435400622892 Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Thu, 31 Aug 2017 17:21:54 +0200 Subject: [PATCH 16/38] lower log level in gfservice --- .../it/near/sdk/geopolis/geofences/GeoFenceService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java b/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java index e07f5833..098dad32 100644 --- a/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java +++ b/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java @@ -264,7 +264,7 @@ private void startGeoFencing(GeofencingRequest request) { // for ActivityCompat#requestPermissions for more details. return; } - NearLog.d(TAG, "startGeofencing"); + NearLog.i(TAG, "startGeofencing"); geofencingClient.addGeofences( request, getGeofencePendingIntent() @@ -313,7 +313,7 @@ private PendingIntent getGeofencePendingIntent() { @Override public void onConnected(@Nullable Bundle bundle) { - NearLog.d(TAG, "onConnected"); + NearLog.i(TAG, "onConnected"); // If we have pending geofences (that need to be started) // we start the geofence now that the client is connected. if (mPendingGeofences != null) { @@ -323,7 +323,7 @@ public void onConnected(@Nullable Bundle bundle) { @Override public void onConnectionSuspended(int i) { - NearLog.d(TAG, "onConnectionSuspended"); + NearLog.i(TAG, "onConnectionSuspended"); } @Override From 0cfabc4cfcd1a1b18954fd361298cb29f64436ff Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Thu, 31 Aug 2017 18:11:51 +0200 Subject: [PATCH 17/38] bump play services to 11.2.0 --- build.gradle | 3 ++- nearit/build.gradle | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/build.gradle b/build.gradle index 6fb77acf..d7aa3326 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:2.3.3' classpath "com.github.dcendents:android-maven-gradle-plugin:1.4.1" - classpath 'com.google.gms:google-services:3.0.0' + classpath 'com.google.gms:google-services:3.1.0' // NOTE: Do not place your application dependencies here; they belong @@ -19,6 +19,7 @@ allprojects { repositories { jcenter() maven { url "https://jitpack.io" } + maven { url "https://maven.google.com" } } } diff --git a/nearit/build.gradle b/nearit/build.gradle index fdccdcb2..2dafde8d 100644 --- a/nearit/build.gradle +++ b/nearit/build.gradle @@ -2,7 +2,7 @@ buildscript { repositories { maven { url 'https://maven.fabric.io/public' } jcenter() - flatDir{ + flatDir { dirs 'libs' } } @@ -64,9 +64,9 @@ def getLatestVersionName = { } } -def playServicesVersion = '11.0.2' +def playServicesVersion = '11.2.0' -allprojects{ +allprojects { version = "${getVersionName()}" } @@ -77,8 +77,8 @@ buildProperties { } android { - compileSdkVersion 25 - buildToolsVersion '25.0.2' + compileSdkVersion 26 + buildToolsVersion '26.0.0' defaultConfig { minSdkVersion 15 @@ -122,26 +122,26 @@ bintray { // Upload docs on ftp -repositories{ +repositories { mavenCentral() } configurations { ftpAntTask } -dependencies{ - ftpAntTask ("org.apache.ant:ant-commons-net:1.8.4") { +dependencies { + ftpAntTask("org.apache.ant:ant-commons-net:1.8.4") { module("commons-net:commons-net:1.4.1") { dependencies "oro:oro:2.0.8:jar" } } } -task injectVersionsInMarkdowns(type: Copy){ +task injectVersionsInMarkdowns(type: Copy) { duplicatesStrategy 'exclude' from('docs/src') { include '*' - filter{ it.replaceAll('@@versionNumber@@', "${getLatestVersionName()}")} - filter{ it.replaceAll('@@playServicesNumber@@', playServicesVersion)} + filter { it.replaceAll('@@versionNumber@@', "${getLatestVersionName()}") } + filter { it.replaceAll('@@playServicesNumber@@', playServicesVersion) } } into 'docs' } From 20d234af7ff3703ecaa78fd1b6d8c69ce07f9919 Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Fri, 1 Sep 2017 09:47:23 +0200 Subject: [PATCH 18/38] add build tools 26 in travis component config components --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 281f5d6e..9e325547 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,8 +12,10 @@ env: android: components: - tools # see https://github.com/travis-ci/travis-ci/issues/6040#issuecomment-219367943) - - build-tools-25.0.2 - platform-tools + - tools + - build-tools-25.0.2 + - build-tools-26.0.0 - android-25 - extra-google-m2repository - extra-android-m2repository From fb78879e2580c1d477aaa913cad57781432cf332 Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Fri, 1 Sep 2017 09:57:27 +0200 Subject: [PATCH 19/38] add more components in travis config --- .travis.yml | 3 ++- nearit/build.gradle | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9e325547..4d0532ae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,8 +15,9 @@ android: - platform-tools - tools - build-tools-25.0.2 - - build-tools-26.0.0 + - build-tools-26.0.1 - android-25 + - android-26 - extra-google-m2repository - extra-android-m2repository - sys-img-armeabi-v7a-android-21 diff --git a/nearit/build.gradle b/nearit/build.gradle index 2dafde8d..251fe8b6 100644 --- a/nearit/build.gradle +++ b/nearit/build.gradle @@ -78,7 +78,7 @@ buildProperties { android { compileSdkVersion 26 - buildToolsVersion '26.0.0' + buildToolsVersion '26.0.1' defaultConfig { minSdkVersion 15 From 828c6d28c23cb61cd15d5ebf00bda9fdf3f1c254 Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Fri, 1 Sep 2017 10:13:20 +0200 Subject: [PATCH 20/38] update sample build tools version --- sample/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sample/build.gradle b/sample/build.gradle index f9623e76..bd5823c4 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -24,8 +24,8 @@ android { config { } } - compileSdkVersion 25 - buildToolsVersion '25.0.2' + compileSdkVersion 26 + buildToolsVersion '26.0.1' defaultConfig { applicationId "com.nearit.sample" minSdkVersion 15 From 1f09264f6165062774ce3a1ace34a60f9cde7349 Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Fri, 1 Sep 2017 10:42:49 +0200 Subject: [PATCH 21/38] new travis config --- .travis.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4d0532ae..766fec8c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,11 +13,9 @@ android: components: - tools # see https://github.com/travis-ci/travis-ci/issues/6040#issuecomment-219367943) - platform-tools - - tools - - build-tools-25.0.2 - build-tools-26.0.1 - - android-25 - - android-26 + - tools + - 'android-26' - extra-google-m2repository - extra-android-m2repository - sys-img-armeabi-v7a-android-21 From 89258668dc447aa1c4376add8b12bc7e2928ff75 Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Fri, 1 Sep 2017 10:54:25 +0200 Subject: [PATCH 22/38] change format of mocked app app_id --- scripts/ci-mock-google-services-setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ci-mock-google-services-setup.sh b/scripts/ci-mock-google-services-setup.sh index 73db8d11..aa1b559a 100644 --- a/scripts/ci-mock-google-services-setup.sh +++ b/scripts/ci-mock-google-services-setup.sh @@ -12,7 +12,7 @@ echo '{ "client": [ { "client_info": { - "mobilesdk_app_id": "0", + "mobilesdk_app_id": "1:123456789000:android:f1bf012572b04063", "android_client_info": { "package_name": "com.nearit.sample" } From 7fce00294115916f7c4a3f0cf2666a028c801bc5 Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Fri, 1 Sep 2017 11:09:06 +0200 Subject: [PATCH 23/38] remove single quotes --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 766fec8c..0803303a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ android: - platform-tools - build-tools-26.0.1 - tools - - 'android-26' + - android-26 - extra-google-m2repository - extra-android-m2repository - sys-img-armeabi-v7a-android-21 From 0735212e6693288aa1c90826ed6eb16525b2c27e Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Fri, 1 Sep 2017 15:03:14 +0200 Subject: [PATCH 24/38] move black-listed implicit intent filter actions for broadcast receiver from manifest to programmatic creation --- nearit/src/main/AndroidManifest.xml | 9 --------- nearit/src/main/java/it/near/sdk/NearItManager.java | 13 +++++++++++++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/nearit/src/main/AndroidManifest.xml b/nearit/src/main/AndroidManifest.xml index f05ddce6..449a52d8 100644 --- a/nearit/src/main/AndroidManifest.xml +++ b/nearit/src/main/AndroidManifest.xml @@ -34,18 +34,9 @@ - - - - - - - Date: Fri, 1 Sep 2017 15:32:00 +0200 Subject: [PATCH 25/38] fix log level --- .../geopolis/geofences/GeoFenceService.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java b/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java index 098dad32..208a8185 100644 --- a/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java +++ b/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java @@ -52,7 +52,7 @@ public class GeoFenceService extends Service implements GoogleApiClient.Connecti @Override public void onCreate() { super.onCreate(); - NearLog.i(TAG, "onCreate()"); + NearLog.v(TAG, "onCreate()"); fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this); geofencingClient = LocationServices.getGeofencingClient(this); } @@ -60,7 +60,7 @@ public void onCreate() { @Override public int onStartCommand(Intent intent, int flags, int startId) { // can be called multiple times - NearLog.i(TAG, "onStartCommand()"); + NearLog.v(TAG, "onStartCommand()"); if (mGoogleApiClient == null || !mGoogleApiClient.isConnected()) { startGoogleApiClient(); } @@ -87,7 +87,7 @@ private void pingSingleLocation() { @Override public void onSuccess(Location location) { if (location != null) { - NearLog.i(TAG, "location: " + location.getLongitude() + " " + location.getLatitude()); + NearLog.v(TAG, "location: " + location.getLongitude() + " " + location.getLatitude()); } } }); @@ -95,7 +95,7 @@ public void onSuccess(Location location) { @Override public void onDestroy() { - NearLog.i(TAG, "onDestroy on geofence service"); + NearLog.v(TAG, "onDestroy on geofence service"); super.onDestroy(); stopAllGeofences(); resetIds(this); @@ -236,7 +236,7 @@ public void stopGeofencing(List idsToremove) { .addOnSuccessListener(new OnSuccessListener() { @Override public void onSuccess(Void aVoid) { - NearLog.i(TAG, "Geofences removed"); + NearLog.v(TAG, "Geofences removed"); } }); } @@ -264,7 +264,7 @@ private void startGeoFencing(GeofencingRequest request) { // for ActivityCompat#requestPermissions for more details. return; } - NearLog.i(TAG, "startGeofencing"); + NearLog.v(TAG, "startGeofencing"); geofencingClient.addGeofences( request, getGeofencePendingIntent() @@ -313,7 +313,7 @@ private PendingIntent getGeofencePendingIntent() { @Override public void onConnected(@Nullable Bundle bundle) { - NearLog.i(TAG, "onConnected"); + NearLog.v(TAG, "onConnected"); // If we have pending geofences (that need to be started) // we start the geofence now that the client is connected. if (mPendingGeofences != null) { @@ -323,17 +323,17 @@ public void onConnected(@Nullable Bundle bundle) { @Override public void onConnectionSuspended(int i) { - NearLog.i(TAG, "onConnectionSuspended"); + NearLog.v(TAG, "onConnectionSuspended"); } @Override public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { - NearLog.i(TAG, "onConnectionFailed"); + NearLog.v(TAG, "onConnectionFailed"); } @Override public void onResult(@NonNull Status status) { - NearLog.i(TAG, "onResult: " + status.getStatusMessage()); + NearLog.v(TAG, "onResult: " + status.getStatusMessage()); } public static String getSharedPrefName(Context context) { From b64f0545cb79c44e29b27c7a53954b1e3e837821 Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Fri, 1 Sep 2017 16:37:33 +0200 Subject: [PATCH 26/38] log levels --- .../java/it/near/sdk/geopolis/geofences/GeoFenceService.java | 2 +- nearit/src/main/java/it/near/sdk/recipes/RecipesApi.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java b/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java index 208a8185..dfebeff4 100644 --- a/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java +++ b/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceService.java @@ -70,7 +70,7 @@ public int onStartCommand(Intent intent, int flags, int startId) { mPendingGeofences = GeofenceNode.toGeofences(nodes); if (GeopolisManager.isRadarStarted(this)) { setGeoFences(nodes); - pingSingleLocation(); + // pingSingleLocation(); } } diff --git a/nearit/src/main/java/it/near/sdk/recipes/RecipesApi.java b/nearit/src/main/java/it/near/sdk/recipes/RecipesApi.java index ab7a371f..cc2bd385 100644 --- a/nearit/src/main/java/it/near/sdk/recipes/RecipesApi.java +++ b/nearit/src/main/java/it/near/sdk/recipes/RecipesApi.java @@ -61,7 +61,7 @@ void processRecipes(final RecipesListener recipeFetcher) { httpClient.nearPost(url.toString(), requestBody, new NearJsonHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { - NearLog.d(TAG, "Got recipes: " + response.toString()); + NearLog.v(TAG, "Got recipes: " + response.toString()); ListMetaBundle recipeListMetaBundle = NearJsonAPIUtils.parseListAndMeta(morpheus, response, Recipe.class); From 7a51b390f1d654b630497e7bff460a55389e5ebe Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Fri, 1 Sep 2017 16:38:12 +0200 Subject: [PATCH 27/38] test descriptions --- .../test/java/it/near/sdk/morpheusnear/MorpheusTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nearit/src/test/java/it/near/sdk/morpheusnear/MorpheusTest.java b/nearit/src/test/java/it/near/sdk/morpheusnear/MorpheusTest.java index e97c566e..d8d86369 100644 --- a/nearit/src/test/java/it/near/sdk/morpheusnear/MorpheusTest.java +++ b/nearit/src/test/java/it/near/sdk/morpheusnear/MorpheusTest.java @@ -126,9 +126,9 @@ public void parseElementWithStringListAttribute() throws Exception { assertThat(testModel.strings, hasItem("two")); assertThat(testModel.strings, hasItem("number three")); } - // TODO inheritance in models - // TODO transitive relationships - // TODO circular relationships + // TODO inheritance in models: B and C extend A, parse a list of b and c elements onto a list of As + // TODO transitive relationships: element in the included array has a relationship with another element in the included array and it gets resolved + // TODO circular relationships: element A as a relationship with B and B has a relationship (same or different name) with A, the creation of those elements instantiation stop at the first cycle private JSONObject readJsonFile(String filename) throws Exception { return TestUtils.readJsonFile(getClass(), MORPHEUS_TEST_RES_FOLDER + "/" + filename); From 4f2c7dbac9c21b12bc871d32454d9a47a797d5fa Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Mon, 4 Sep 2017 10:42:29 +0200 Subject: [PATCH 28/38] new altbeacon version (bugfixes) --- nearit/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nearit/build.gradle b/nearit/build.gradle index 0b6accd1..77f240ea 100644 --- a/nearit/build.gradle +++ b/nearit/build.gradle @@ -154,7 +154,7 @@ dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.loopj.android:android-async-http:1.4.9' compile 'com.google.code.gson:gson:2.8.0' - compile 'org.altbeacon:android-beacon-library:2.12.1' + compile 'org.altbeacon:android-beacon-library:2.12.2' compile "com.google.firebase:firebase-messaging:${playServicesVersion}" compile "com.google.firebase:firebase-core:${playServicesVersion}" compile "com.google.android.gms:play-services-location:${playServicesVersion}" From 75aff550e32c81a1348289472898cb464b57e2a7 Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Mon, 4 Sep 2017 16:02:31 +0200 Subject: [PATCH 29/38] register for location updates while the app is in the foreground for lowering geofence enter events --- .../it/near/sdk/geopolis/GeopolisManager.java | 3 +- .../geopolis/geofences/GeoFenceMonitor.java | 47 ++++++++++++++++++- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/nearit/src/main/java/it/near/sdk/geopolis/GeopolisManager.java b/nearit/src/main/java/it/near/sdk/geopolis/GeopolisManager.java index 610d51dd..135538a6 100644 --- a/nearit/src/main/java/it/near/sdk/geopolis/GeopolisManager.java +++ b/nearit/src/main/java/it/near/sdk/geopolis/GeopolisManager.java @@ -11,8 +11,6 @@ import org.json.JSONException; import org.json.JSONObject; -import java.io.Serializable; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -298,5 +296,6 @@ private void setRadarState(boolean b) { public void initLifecycle(Application application) { altBeaconMonitor.initAppLifecycleMonitor(application); + geofenceMonitor.initAppLifecycleMonitor(application); } } diff --git a/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceMonitor.java b/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceMonitor.java index 923bd12b..9158c89c 100644 --- a/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceMonitor.java +++ b/nearit/src/main/java/it/near/sdk/geopolis/geofences/GeoFenceMonitor.java @@ -1,10 +1,19 @@ package it.near.sdk.geopolis.geofences; +import android.Manifest; +import android.app.Application; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.PackageManager; import android.os.Parcelable; +import android.support.v4.app.ActivityCompat; +import com.google.android.gms.location.FusedLocationProviderClient; +import com.google.android.gms.location.LocationCallback; +import com.google.android.gms.location.LocationRequest; +import com.google.android.gms.location.LocationResult; +import com.google.android.gms.location.LocationServices; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; @@ -15,22 +24,27 @@ import it.near.sdk.geopolis.GeopolisManager; import it.near.sdk.geopolis.Node; +import it.near.sdk.logging.NearLog; +import it.near.sdk.utils.AppVisibilityDetector; + +import static android.Manifest.permission.ACCESS_COARSE_LOCATION; /** * Created by cattaneostefano on 28/09/2016. */ -public class GeoFenceMonitor { +public class GeoFenceMonitor implements AppVisibilityDetector.AppVisibilityCallback { private static final String TAG = "GeoFenceMonitor"; private static final String CURRENT_GEOFENCES = "current_geofences"; private Context mContext; private List currentGeofences; - GeoFenceService geoFenceService; private static final String PREFS_SUFFIX = "NearGeoMonitor"; + private FusedLocationProviderClient mFusedLocationClient; public GeoFenceMonitor(Context mContext) { this.mContext = mContext; + mFusedLocationClient = LocationServices.getFusedLocationProviderClient(mContext); } /** @@ -130,4 +144,33 @@ public static List geofencesOnExit(List nodes, Node node) { } return filterGeofence(toListen); } + + public void initAppLifecycleMonitor(Application application) { + AppVisibilityDetector.init(application, this); + } + + @Override + public void onAppGotoForeground() { + if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(mContext, ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + return; + } + NearLog.i(TAG, "Requesting single location"); + LocationRequest mLocationRequest = new LocationRequest(); + mLocationRequest.setInterval(5000L); + mLocationRequest.setFastestInterval(2000L); + mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); + mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, null); + } + + @Override + public void onAppGotoBackground() { + mFusedLocationClient.removeLocationUpdates(mLocationCallback); + } + + LocationCallback mLocationCallback = new LocationCallback() { + @Override + public void onLocationResult(LocationResult locationResult) { + NearLog.i(TAG, "Got location update"); + } + }; } From 819c7e37966ab888aae856c7f79a848a8fc9fb6d Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Mon, 4 Sep 2017 16:53:46 +0200 Subject: [PATCH 30/38] register for location updates with an intent --- nearit/src/main/AndroidManifest.xml | 3 ++ .../geopolis/geofences/GeoFenceMonitor.java | 28 +++++++++++++++---- .../geofences/LocationUpdatesReceiver.java | 17 +++++++++++ 3 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 nearit/src/main/java/it/near/sdk/geopolis/geofences/LocationUpdatesReceiver.java diff --git a/nearit/src/main/AndroidManifest.xml b/nearit/src/main/AndroidManifest.xml index 449a52d8..f1354a33 100644 --- a/nearit/src/main/AndroidManifest.xml +++ b/nearit/src/main/AndroidManifest.xml @@ -38,6 +38,9 @@ + ) currentGeofences); mContext.startService(serviceIntent); + registerForLocationUpdates(); } public void stopGFRadar() { mContext.stopService(new Intent(mContext, GeoFenceService.class)); + mFusedLocationClient.removeLocationUpdates(getPendingIntent()); + } + + private void registerForLocationUpdates() { + if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + return; + } + LocationRequest mLocationRequest = new LocationRequest(); + mLocationRequest.setInterval(5000L); + mLocationRequest.setFastestInterval(2000L); + mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); + mFusedLocationClient.requestLocationUpdates(mLocationRequest, getPendingIntent()); + } + + private PendingIntent getPendingIntent() { + Intent intent = new Intent(mContext, LocationUpdatesReceiver.class); + intent.setAction(LocationUpdatesReceiver.ACTION_PROCESS_UPDATES); + return PendingIntent.getBroadcast(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); } /** @@ -151,7 +169,7 @@ public void initAppLifecycleMonitor(Application application) { @Override public void onAppGotoForeground() { - if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(mContext, ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + /* if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(mContext, ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return; } NearLog.i(TAG, "Requesting single location"); @@ -159,12 +177,12 @@ public void onAppGotoForeground() { mLocationRequest.setInterval(5000L); mLocationRequest.setFastestInterval(2000L); mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); - mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, null); + mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, null);*/ } @Override public void onAppGotoBackground() { - mFusedLocationClient.removeLocationUpdates(mLocationCallback); + /*mFusedLocationClient.removeLocationUpdates(mLocationCallback);*/ } LocationCallback mLocationCallback = new LocationCallback() { diff --git a/nearit/src/main/java/it/near/sdk/geopolis/geofences/LocationUpdatesReceiver.java b/nearit/src/main/java/it/near/sdk/geopolis/geofences/LocationUpdatesReceiver.java new file mode 100644 index 00000000..c96efb09 --- /dev/null +++ b/nearit/src/main/java/it/near/sdk/geopolis/geofences/LocationUpdatesReceiver.java @@ -0,0 +1,17 @@ +package it.near.sdk.geopolis.geofences; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +import it.near.sdk.logging.NearLog; + +public class LocationUpdatesReceiver extends BroadcastReceiver { + private static final String TAG = "LocationUpdatesReceiver"; + public static final String ACTION_PROCESS_UPDATES = "kjhdbfds"; + + @Override + public void onReceive(Context context, Intent intent) { + NearLog.d(TAG, "got location update"); + } +} From 27071380c338b318e35fdb5a778936a7c0979eac Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Mon, 4 Sep 2017 16:56:41 +0200 Subject: [PATCH 31/38] test caching for android components --- .travis.yml | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0803303a..5bd812ca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,26 +3,43 @@ dist: precise sudo: required jdk: - oraclejdk8 +before_cache: + # Do not cache a few Gradle files/directories (see https://docs.travis-ci.com/user/languages/java/#Caching) + - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock + - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ +cache: + directories: + # Android SDK + - $HOME/android-sdk-dl + - $HOME/android-sdk + + # Gradle dependencies + - $HOME/.gradle/caches/ + - $HOME/.gradle/wrapper/ + + # Android build cache (see http://tools.android.com/tech-docs/build-cache) + - $HOME/.android/build-cache env: global: # switch glibc to a memory conserving mode - MALLOC_ARENA_MAX=2 # wait up to 10 minutes for adb to connect to emulator - ADB_INSTALL_TIMEOUT=10 -android: - components: - - tools # see https://github.com/travis-ci/travis-ci/issues/6040#issuecomment-219367943) - - platform-tools - - build-tools-26.0.1 - - tools - - android-26 - - extra-google-m2repository - - extra-android-m2repository - - sys-img-armeabi-v7a-android-21 - licenses: - - 'android-sdk-preview-license-52d11cd2' - - 'android-sdk-license-.+' - - 'google-gdk-license-.+' +install: + # Download and unzip the Android SDK tools (if not already there thanks to the cache mechanism) + - if test ! -e $HOME/android-sdk-dl/tools_r25.2.5-linux.zip ; then curl https://dl.google.com/android/repository/tools_r25.2.5-linux.zip > $HOME/android-sdk-dl/tools_r25.2.5-linux.zip ; fi + - unzip -n $HOME/android-sdk-dl/tools_r25.2.5-linux.zip -d $HOME/android-sdk + + # Install or update Android SDK components (will not do anything if already up to date thanks to the cache mechanism) + - echo y | $HOME/android-sdk/tools/bin/sdkmanager 'tools' + - echo y | $HOME/android-sdk/tools/bin/sdkmanager 'platform-tools' + - echo y | $HOME/android-sdk/tools/bin/sdkmanager 'build-tools;25.0.2' + - echo y | $HOME/android-sdk/tools/bin/sdkmanager 'platforms;android-25' + - echo y | $HOME/android-sdk/tools/bin/sdkmanager 'extras;android;m2repository' + - echo y | $HOME/android-sdk/tools/bin/sdkmanager 'extras;google;google_play_services' + - echo y | $HOME/android-sdk/tools/bin/sdkmanager 'extras;google;m2repository' +env: + - ANDROID_HOME=$HOME/android-sdk before_install: - export TZ=Australia/Canberra script: From a5e7b14ff8dac74fe0e607e038607aba3f1d53b3 Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Mon, 4 Sep 2017 17:39:19 +0200 Subject: [PATCH 32/38] lower log level, non-random action name --- .../near/sdk/geopolis/geofences/LocationUpdatesReceiver.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nearit/src/main/java/it/near/sdk/geopolis/geofences/LocationUpdatesReceiver.java b/nearit/src/main/java/it/near/sdk/geopolis/geofences/LocationUpdatesReceiver.java index c96efb09..1cfd1ad6 100644 --- a/nearit/src/main/java/it/near/sdk/geopolis/geofences/LocationUpdatesReceiver.java +++ b/nearit/src/main/java/it/near/sdk/geopolis/geofences/LocationUpdatesReceiver.java @@ -8,10 +8,10 @@ public class LocationUpdatesReceiver extends BroadcastReceiver { private static final String TAG = "LocationUpdatesReceiver"; - public static final String ACTION_PROCESS_UPDATES = "kjhdbfds"; + public static final String ACTION_PROCESS_UPDATES = "empty_action"; @Override public void onReceive(Context context, Intent intent) { - NearLog.d(TAG, "got location update"); + NearLog.i(TAG, "got location update"); } } From 2abf4228ab2b26ae060da953fe4a59516b995edd Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Mon, 4 Sep 2017 17:52:37 +0200 Subject: [PATCH 33/38] revert useless cache "improvements" --- .travis.yml | 45 ++++++++++++++------------------------------- 1 file changed, 14 insertions(+), 31 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5bd812ca..0803303a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,43 +3,26 @@ dist: precise sudo: required jdk: - oraclejdk8 -before_cache: - # Do not cache a few Gradle files/directories (see https://docs.travis-ci.com/user/languages/java/#Caching) - - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock - - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ -cache: - directories: - # Android SDK - - $HOME/android-sdk-dl - - $HOME/android-sdk - - # Gradle dependencies - - $HOME/.gradle/caches/ - - $HOME/.gradle/wrapper/ - - # Android build cache (see http://tools.android.com/tech-docs/build-cache) - - $HOME/.android/build-cache env: global: # switch glibc to a memory conserving mode - MALLOC_ARENA_MAX=2 # wait up to 10 minutes for adb to connect to emulator - ADB_INSTALL_TIMEOUT=10 -install: - # Download and unzip the Android SDK tools (if not already there thanks to the cache mechanism) - - if test ! -e $HOME/android-sdk-dl/tools_r25.2.5-linux.zip ; then curl https://dl.google.com/android/repository/tools_r25.2.5-linux.zip > $HOME/android-sdk-dl/tools_r25.2.5-linux.zip ; fi - - unzip -n $HOME/android-sdk-dl/tools_r25.2.5-linux.zip -d $HOME/android-sdk - - # Install or update Android SDK components (will not do anything if already up to date thanks to the cache mechanism) - - echo y | $HOME/android-sdk/tools/bin/sdkmanager 'tools' - - echo y | $HOME/android-sdk/tools/bin/sdkmanager 'platform-tools' - - echo y | $HOME/android-sdk/tools/bin/sdkmanager 'build-tools;25.0.2' - - echo y | $HOME/android-sdk/tools/bin/sdkmanager 'platforms;android-25' - - echo y | $HOME/android-sdk/tools/bin/sdkmanager 'extras;android;m2repository' - - echo y | $HOME/android-sdk/tools/bin/sdkmanager 'extras;google;google_play_services' - - echo y | $HOME/android-sdk/tools/bin/sdkmanager 'extras;google;m2repository' -env: - - ANDROID_HOME=$HOME/android-sdk +android: + components: + - tools # see https://github.com/travis-ci/travis-ci/issues/6040#issuecomment-219367943) + - platform-tools + - build-tools-26.0.1 + - tools + - android-26 + - extra-google-m2repository + - extra-android-m2repository + - sys-img-armeabi-v7a-android-21 + licenses: + - 'android-sdk-preview-license-52d11cd2' + - 'android-sdk-license-.+' + - 'google-gdk-license-.+' before_install: - export TZ=Australia/Canberra script: From fb7a87cda01a8215c13b9ed8ece19f041d7b5236 Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Tue, 5 Sep 2017 10:10:32 +0200 Subject: [PATCH 34/38] testing cache on null fields and map with null values --- .../it/near/sdk/reactions/CacherTest.java | 67 ++++++++++++++++--- .../reactions/testmodels/ModelForCache.java | 15 +++-- 2 files changed, 65 insertions(+), 17 deletions(-) diff --git a/nearit/src/test/java/it/near/sdk/reactions/CacherTest.java b/nearit/src/test/java/it/near/sdk/reactions/CacherTest.java index fa5f62b3..ae64857e 100644 --- a/nearit/src/test/java/it/near/sdk/reactions/CacherTest.java +++ b/nearit/src/test/java/it/near/sdk/reactions/CacherTest.java @@ -37,38 +37,83 @@ public class CacherTest { @Mock SharedPreferences.Editor editor; - List list; + private List list; @Before public void setUp() throws Exception { when(sharedPreferences.edit()).thenReturn(editor); when(editor.putString(anyString(), anyString())).thenReturn(editor); cacher = new Cacher<>(sharedPreferences); - buildList(); } - private void buildList() { + @Test + public void simplePersistence() throws Exception { list = Lists.newArrayList( - new ModelForCache("string1", 1, 1L, buildHash(1)), - new ModelForCache("string2", 2, 2L, buildHash(2)) + new ModelForCache("string1", 1, 1L, buildMap(1)), + new ModelForCache("string2", 2, 2L, buildMap(2)) ); + cacher.persistList(list); + // capture argument + ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); + verify(editor).putString(eq(KEY_LIST), captor.capture()); + String stringifiedList = captor.getValue(); + when(sharedPreferences.getString(eq(KEY_LIST), anyString())).thenReturn(stringifiedList); + Type type = new TypeToken>() { + }.getType(); + List modelForCaches = cacher.loadList(type); + assertThat(modelForCaches, contains(list.toArray())); } - private Map buildHash(int i) { - Map map = Maps.newHashMap(); - map.put("value", Double.valueOf(i)); - return map; + @Test + public void nullValuesPersistance() throws Exception { + list = Lists.newArrayList( + new ModelForCache(null, 0, 0L, null) + ); + cacher.persistList(list); + // capture argument + ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); + verify(editor).putString(eq(KEY_LIST), captor.capture()); + String stringifiedList = captor.getValue(); + when(sharedPreferences.getString(eq(KEY_LIST), anyString())).thenReturn(stringifiedList); + Type type = new TypeToken>() { + }.getType(); + List modelForCaches = cacher.loadList(type); + assertThat(modelForCaches, contains(list.toArray())); } @Test - public void simplePersistence() throws Exception { + public void hashMapWithNullValues() throws Exception { + Map map = Maps.newLinkedHashMap(); + map.put("string", "my_string"); + map.put("int", ((Integer) 3).doubleValue()); + map.put("long", (Double) 9D); + map.put("list", Lists.newArrayList("one", "two")); + map.put("null_object", null); + list = Lists.newArrayList( + new ModelForCache(null, 0, 0L, map) + ); cacher.persistList(list); + // capture argument ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); verify(editor).putString(eq(KEY_LIST), captor.capture()); String stringifiedList = captor.getValue(); when(sharedPreferences.getString(eq(KEY_LIST), anyString())).thenReturn(stringifiedList); - Type type = new TypeToken>() {}.getType(); + Type type = new TypeToken>() { + }.getType(); List modelForCaches = cacher.loadList(type); assertThat(modelForCaches, contains(list.toArray())); } + + private void buildList() { + list = Lists.newArrayList( + new ModelForCache("string1", 1, 1L, buildMap(1)), + new ModelForCache("string2", 2, 2L, buildMap(2)) + ); + } + + private Map buildMap(int i) { + Map map = Maps.newLinkedHashMap(); + map.put("value", (double) i); + return map; + } } diff --git a/nearit/src/test/java/it/near/sdk/reactions/testmodels/ModelForCache.java b/nearit/src/test/java/it/near/sdk/reactions/testmodels/ModelForCache.java index 337dbc4b..3ebfefc8 100644 --- a/nearit/src/test/java/it/near/sdk/reactions/testmodels/ModelForCache.java +++ b/nearit/src/test/java/it/near/sdk/reactions/testmodels/ModelForCache.java @@ -1,15 +1,19 @@ package it.near.sdk.reactions.testmodels; +import android.support.annotation.Nullable; + import java.util.Map; public class ModelForCache { + @Nullable public String _string; public int _integer; public long _long; + @Nullable public Map _hashMap; - public ModelForCache(String _string, int _integer, long _long, Map _hashMap) { + public ModelForCache(@Nullable String _string, int _integer, long _long, Map _hashMap) { this._string = _string; this._integer = _integer; this._long = _long; @@ -25,17 +29,16 @@ public boolean equals(Object o) { if (_integer != that._integer) return false; if (_long != that._long) return false; - if (!_string.equals(that._string)) return false; - return _hashMap.equals(that._hashMap); - + if (_string != null ? !_string.equals(that._string) : that._string != null) return false; + return _hashMap != null ? _hashMap.equals(that._hashMap) : that._hashMap == null; } @Override public int hashCode() { - int result = _string.hashCode(); + int result = _string != null ? _string.hashCode() : 0; result = 31 * result + _integer; result = 31 * result + (int) (_long ^ (_long >>> 32)); - result = 31 * result + _hashMap.hashCode(); + result = 31 * result + (_hashMap != null ? _hashMap.hashCode() : 0); return result; } } From 41eaaec3ff8205875d4c5c8ffa85f580222dc32b Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Tue, 5 Sep 2017 16:46:47 +0200 Subject: [PATCH 35/38] remove unused code --- .../geofences/NearGeofenceTransitionsIntentService.java | 8 +------- .../src/test/java/it/near/sdk/reactions/CacherTest.java | 1 + 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/nearit/src/main/java/it/near/sdk/geopolis/geofences/NearGeofenceTransitionsIntentService.java b/nearit/src/main/java/it/near/sdk/geopolis/geofences/NearGeofenceTransitionsIntentService.java index 353e18e7..773ab5b4 100644 --- a/nearit/src/main/java/it/near/sdk/geopolis/geofences/NearGeofenceTransitionsIntentService.java +++ b/nearit/src/main/java/it/near/sdk/geopolis/geofences/NearGeofenceTransitionsIntentService.java @@ -6,16 +6,14 @@ import android.content.SharedPreferences; import android.text.TextUtils; -import android.widget.Toast; - import com.google.android.gms.location.Geofence; import com.google.android.gms.location.GeofencingEvent; import java.util.ArrayList; import java.util.List; -import it.near.sdk.geopolis.GeopolisManager; import it.near.sdk.R; +import it.near.sdk.geopolis.GeopolisManager; import it.near.sdk.logging.NearLog; /** @@ -82,10 +80,6 @@ private void notifyEventOnGeofence(Geofence triggeringGeofence, int geofenceTran sendBroadcast(intent); } - private void sendNotification(String geofenceTransitionDetails, int geofenceTransition) { - Toast.makeText(this, "Geofence event", Toast.LENGTH_SHORT).show(); - } - /** * Posts a notification in the notification bar when a transition is detected. * If the user clicks the notification, control goes to the MainActivity. diff --git a/nearit/src/test/java/it/near/sdk/reactions/CacherTest.java b/nearit/src/test/java/it/near/sdk/reactions/CacherTest.java index ae64857e..34f6b7a2 100644 --- a/nearit/src/test/java/it/near/sdk/reactions/CacherTest.java +++ b/nearit/src/test/java/it/near/sdk/reactions/CacherTest.java @@ -85,6 +85,7 @@ public void nullValuesPersistance() throws Exception { public void hashMapWithNullValues() throws Exception { Map map = Maps.newLinkedHashMap(); map.put("string", "my_string"); + // this looks stupid, but gson parses every map value that looks like a number to a Double. Without this, the equals check breaks map.put("int", ((Integer) 3).doubleValue()); map.put("long", (Double) 9D); map.put("list", Lists.newArrayList("one", "two")); From efbbfd9acf758404c593fe1c715b0493c0985f07 Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Fri, 22 Sep 2017 17:03:41 +0200 Subject: [PATCH 36/38] bump play services to 11.4.0. Fixes #15 --- nearit/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nearit/build.gradle b/nearit/build.gradle index 63a3620c..29703bb0 100644 --- a/nearit/build.gradle +++ b/nearit/build.gradle @@ -64,7 +64,7 @@ def getLatestVersionName = { } } -def playServicesVersion = '11.2.0' +def playServicesVersion = '11.4.0' allprojects { version = "${getVersionName()}" From 0f578f965b5723d55902893e8e0c3409653fb1e6 Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Fri, 22 Sep 2017 17:08:40 +0200 Subject: [PATCH 37/38] update docs --- docs/location-based-notifications.md | 4 ++-- docs/push-notifications.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/location-based-notifications.md b/docs/location-based-notifications.md index 15fc7ef6..7d533736 100644 --- a/docs/location-based-notifications.md +++ b/docs/location-based-notifications.md @@ -21,8 +21,8 @@ To learn how to deal with in-app content once the user taps on the notification, If you want to customize your notifications, see this [section](custom-bkg-notification.md). ___ -**WARNING**: If you experience build or runtime problems with google play services components, make sure to include the 10.2.0 version of any gms dependency in your app. Example: +**WARNING**: If you experience build or runtime problems with google play services components, make sure to include the 11.4.0 version of any gms dependency in your app. Example: ```xml -compile 'com.google.android.gms:play-services-analytics:10.2.0' +compile 'com.google.android.gms:play-services-analytics:11.4.0' ``` Conflicting play services version may result in compile-time and run-time errors. diff --git a/docs/push-notifications.md b/docs/push-notifications.md index efb29ca6..4dd6f51b 100644 --- a/docs/push-notifications.md +++ b/docs/push-notifications.md @@ -63,8 +63,8 @@ If you want to customize your notifications, see this [section](custom-bkg-notif ___ -**WARNING**: If you experience build or runtime problems with google play services components, make sure to include the 10.2.0 version of any gms dependency in your app. Example: +**WARNING**: If you experience build or runtime problems with google play services components, make sure to include the 11.4.0 version of any gms dependency in your app. Example: ```xml -compile 'com.google.android.gms:play-services-analytics:10.2.0' +compile 'com.google.android.gms:play-services-analytics:11.4.0' ``` Conflicting play services version may result in compile-time and run-time errors. From 39730b69dae3e4527fa6dae2fa90011fc42a151e Mon Sep 17 00:00:00 2001 From: Cattaneo Stefano Date: Mon, 25 Sep 2017 10:21:49 +0200 Subject: [PATCH 38/38] update references --- README.md | 2 +- docs/installation.md | 2 +- sample/build.gradle | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5c6a7658..4054938e 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ To start using the SDK, include this in your app *build.gradle* ```java dependencies { - compile 'it.near.sdk:nearit:2.2.0' + compile 'it.near.sdk:nearit:2.2.2' } ``` diff --git a/docs/installation.md b/docs/installation.md index c097ad4c..99743b1b 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -7,7 +7,7 @@ To start using the SDK, include this in your app *build.gradle* ```java dependencies { - compile 'it.near.sdk:nearit:2.2.0' + compile 'it.near.sdk:nearit:2.2.2' } ``` In AndroidManifest.xml, add the following element as a child of the `` element, by inserting it just before the closing `` tag: diff --git a/sample/build.gradle b/sample/build.gradle index bd5823c4..276496b0 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -55,7 +55,7 @@ dependencies { exclude group: 'com.android.support', module: 'support-annotations' }) - // compile 'it.near.sdk:nearit:2.1.39' + // compile 'it.near.sdk:nearit:2.2.2' compile project(':nearit') compile 'com.android.support:appcompat-v7:24.2.1'