Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update gradle and fix android O foregroundService #5

Merged
merged 6 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android:
- tools
- platform-tools
- tools
- build-tools-26.0.2
- android-26
- build-tools-28.0.3
- android-28
- extra-android-m2repository
- extra-google-m2repository
- extra-google-google_play_services
Expand Down
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.smartLocationVersion = "3.3.3"
ext.smartLocationVersion = "3.4.1"

// Common dependencies
ext.robolectricVersion = "3.1"
ext.mockitoVersion = "2.0.86-beta"
ext.mockitoVersion = "2.25.0"
ext.junitVersion = "4.12"

repositories {
mavenCentral()
maven { url "https://maven.google.com" }
jcenter()
google()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-rc2'
classpath 'com.android.tools.build:gradle:3.3.2'
}
}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Oct 14 10:52:55 BST 2017
#Thu Mar 14 17:59:57 WIB 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
114 changes: 29 additions & 85 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,117 +1,61 @@
buildscript {
repositories {
mavenCentral()
google()
jcenter()
}
}

apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
apply plugin: 'maven'
apply plugin: 'signing'


version smartLocationVersion
group 'io.nlopez.smartlocation'

dependencies {
repositories {
jcenter()
mavenCentral()
google()
maven { url "https://maven.google.com" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
compile 'com.google.android.gms:play-services-location:11.4.2'
compile 'com.android.support:support-annotations:26.1.0'
testCompile "junit:junit:$junitVersion"
testCompile "org.robolectric:robolectric:$robolectricVersion"
testCompile "org.robolectric:robolectric-shadows:$robolectricVersion"
testCompile "org.mockito:mockito-core:$mockitoVersion"
api 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.android.support:support-annotations:28.0.0'
testImplementation "junit:junit:$junitVersion"
testImplementation "org.robolectric:robolectric:$robolectricVersion"
testImplementation "org.robolectric:robolectric-shadows:$robolectricVersion"
testImplementation "org.mockito:mockito-core:$mockitoVersion"
}

android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
compileSdkVersion 28
buildToolsVersion '28.0.3'

buildTypes {
defaultConfig {
minSdkVersion 14
targetSdkVersion 26
minSdkVersion 19
targetSdkVersion 28
versionCode 20006
versionName version
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
minifyEnabled false
}
}

lintOptions {
checkReleaseBuilds false
//If you want to continue even if errors found use following line
abortOnError false
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}

}

android.libraryVariants
publishing {
publications {
maven(MavenPublication) {
artifact "build/libs/SmartLocation-${version}.aar"
artifactId 'library'
}
}
}

def isReleaseBuild() {
return version.contains("SNAPSHOT") == false
}

def getProperty(project, property) {
return project.hasProperty(property) ? project.property(property) : ""
}

signing {
required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}

uploadArchives {
configuration = configurations.archives
repositories.mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

repository(url: getProperty(project, "sonatypeRepo")) {
authentication(userName: getProperty(project, "sonatypeUsername"),
password: getProperty(project, "sonatypePassword"))
}
snapshotRepository(url: getProperty(project, "sonatypeSnapshotRepo")) {
authentication(userName: getProperty(project, "sonatypeUsername"),
password: getProperty(project, "sonatypePassword"))
}

pom.project {
name 'Smart Location Library'
packaging 'aar'
description 'This library handles all the boilerplate and repetitive code used when playing with Locations in Android projects.'
url 'https://github.com/mrmans0n/smart-location-lib'
artifactId 'library'

scm {
url 'scm:[email protected]:mrmans0n/smart-location-lib.git'
connection 'scm:[email protected]:mrmans0n/smart-location-lib.git'
developerConnection 'scm:[email protected]:mrmans0n/smart-location-lib.git'
}

licenses {
license {
name 'MIT license'
url 'http://www.opensource.org/licenses/mit-license.php'
distribution 'repo'
}
}

developers {
developer {
id 'mrmans0n'
name 'Nacho Lopez'
email '[email protected]'
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.nlopez.smartlocation.activity.providers;

import android.app.Activity;
import android.app.IntentService;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
Expand All @@ -10,6 +9,7 @@
import android.content.IntentSender;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.JobIntentService;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
Expand All @@ -35,7 +35,7 @@ public class ActivityGooglePlayServicesProvider implements ActivityProvider, Goo
private static final String GMS_ID = "GMS";
private static final String BROADCAST_INTENT_ACTION = ActivityGooglePlayServicesProvider.class.getCanonicalName() + ".DETECTED_ACTIVITY";
private static final String DETECTED_ACTIVITY_EXTRA_ID = "activity";

private final GooglePlayServicesListener googlePlayServicesListener;
private GoogleApiClient client;
private Logger logger;
private OnActivityUpdatedListener listener;
Expand All @@ -45,8 +45,16 @@ public class ActivityGooglePlayServicesProvider implements ActivityProvider, Goo
private boolean stopped = false;
private PendingIntent pendingIntent;
private ActivityParams activityParams;
private final GooglePlayServicesListener googlePlayServicesListener;

private BroadcastReceiver activityReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (BROADCAST_INTENT_ACTION.equals(intent.getAction()) && intent.hasExtra(DETECTED_ACTIVITY_EXTRA_ID)) {
logger.d("sending new activity");
DetectedActivity detectedActivity = intent.getParcelableExtra(DETECTED_ACTIVITY_EXTRA_ID);
notifyActivity(detectedActivity);
}
}
};

public ActivityGooglePlayServicesProvider() {
this(null);
Expand Down Expand Up @@ -100,9 +108,9 @@ private void startUpdating(ActivityParams params) {
// TODO wait until the connection is done and retry
if (client.isConnected()) {
pendingIntent = PendingIntent.getService(context, 0, new Intent(context, ActivityRecognitionService.class),
PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent.FLAG_UPDATE_CURRENT);
ActivityRecognition.ActivityRecognitionApi.requestActivityUpdates(client, params.getInterval(),
pendingIntent).setResultCallback(this);
pendingIntent).setResultCallback(this);
}
}

Expand Down Expand Up @@ -167,26 +175,28 @@ private void notifyActivity(final DetectedActivity detectedActivity) {
}
}

@Override
public void onResult(@NonNull Status status) {
if (status.isSuccess()) {
logger.d("Activity update request successful");
} else if (status.hasResolution() && context instanceof Activity) {
logger.w("Unable to register, but we can solve this - will startActivityForResult expecting result code " + RESULT_CODE + " (if received, please try again)");

private BroadcastReceiver activityReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (BROADCAST_INTENT_ACTION.equals(intent.getAction()) && intent.hasExtra(DETECTED_ACTIVITY_EXTRA_ID)) {
logger.d("sending new activity");
DetectedActivity detectedActivity = intent.getParcelableExtra(DETECTED_ACTIVITY_EXTRA_ID);
notifyActivity(detectedActivity);
try {
status.startResolutionForResult((Activity) context, RESULT_CODE);
} catch (IntentSender.SendIntentException e) {
logger.e(e, "problem with startResolutionForResult");
}
} else {
// No recovery. Weep softly or inform the user.
logger.e("Registering failed: " + status.getStatusMessage());
}
};

public static class ActivityRecognitionService extends IntentService {
}

public ActivityRecognitionService() {
super(ActivityRecognitionService.class.getSimpleName());
}
public static class ActivityRecognitionService extends JobIntentService {

@Override
protected void onHandleIntent(Intent intent) {
protected void onHandleWork(@NonNull Intent intent) {
if (ActivityRecognitionResult.hasResult(intent)) {
ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
DetectedActivity mostProbableActivity = result.getMostProbableActivity();
Expand All @@ -196,24 +206,7 @@ protected void onHandleIntent(Intent intent) {
activityIntent.putExtra(DETECTED_ACTIVITY_EXTRA_ID, mostProbableActivity);
sendBroadcast(activityIntent);
}
}
}

@Override
public void onResult(@NonNull Status status) {
if (status.isSuccess()) {
logger.d("Activity update request successful");
} else if (status.hasResolution() && context instanceof Activity) {
logger.w("Unable to register, but we can solve this - will startActivityForResult expecting result code " + RESULT_CODE + " (if received, please try again)");

try {
status.startResolutionForResult((Activity) context, RESULT_CODE);
} catch (IntentSender.SendIntentException e) {
logger.e(e, "problem with startResolutionForResult");
}
} else {
// No recovery. Weep softly or inform the user.
logger.e("Registering failed: " + status.getStatusMessage());
}
}

Expand Down
Loading