diff --git a/.travis.yml b/.travis.yml
index 6627bce..c85b660 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,11 +7,10 @@ android:
components:
- platform-tools
- tools
- - build-tools-25.0.2
- - android-25
- - extra-android-m2repository
before_script:
- - chmod +x gradlew
+ # Install SDK license so Android Gradle plugin can install deps.
+ - mkdir "$ANDROID_HOME/licenses" || true
+ - echo "8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
script: "./gradlew build"
diff --git a/app/build.gradle b/app/build.gradle
index 5c201a4..fcd5c01 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,13 +1,12 @@
apply plugin: 'com.android.application'
android {
- compileSdkVersion 25
- buildToolsVersion "25.0.2"
+ compileSdkVersion 26
defaultConfig {
applicationId "com.commit451.lifeline.sample"
minSdkVersion 14
- targetSdkVersion 25
+ targetSdkVersion 26
versionCode 1
versionName "1.0"
}
@@ -23,7 +22,6 @@ android {
}
dependencies {
- compile fileTree(include: ['*.jar'], dir: 'libs')
- compile 'com.android.support:appcompat-v7:25.2.0'
+ compile 'com.android.support:appcompat-v7:26.1.0'
compile project(':lifeline')
}
diff --git a/app/src/main/java/com/commit451/lifeline/sample/App.java b/app/src/main/java/com/commit451/lifeline/sample/App.java
index 48166a5..414efcc 100644
--- a/app/src/main/java/com/commit451/lifeline/sample/App.java
+++ b/app/src/main/java/com/commit451/lifeline/sample/App.java
@@ -1,8 +1,10 @@
package com.commit451.lifeline.sample;
import android.app.Application;
+import android.widget.Toast;
import com.commit451.lifeline.Lifeline;
+import com.commit451.lifeline.OnBackgroundedListener;
/**
* Here is where you would initialize {@link com.commit451.lifeline.Lifeline}
@@ -13,5 +15,12 @@ public class App extends Application {
public void onCreate() {
super.onCreate();
Lifeline.init(this);
+ Lifeline.register(new OnBackgroundedListener() {
+ @Override
+ public void onBackgrounded() {
+ Toast.makeText(App.this, "On backgrounded", Toast.LENGTH_SHORT)
+ .show();
+ }
+ });
}
}
diff --git a/build.gradle b/build.gradle
index 32ed3fc..21c8832 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,21 +1,18 @@
-// Top-level build file where you can add configuration options common to all sub-projects/modules.
-
buildscript {
repositories {
jcenter()
+ google()
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.3.0'
+ classpath 'com.android.tools.build:gradle:3.0.0-beta7'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
-
- // NOTE: Do not place your application dependencies here; they belong
- // in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
+ google()
}
}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index fc393b2..97ae4ba 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Wed Mar 08 10:06:00 CST 2017
+#Mon Oct 09 11:06:41 CDT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
diff --git a/lifeline/build.gradle b/lifeline/build.gradle
index b5318dd..06d37e6 100644
--- a/lifeline/build.gradle
+++ b/lifeline/build.gradle
@@ -1,12 +1,11 @@
apply plugin: 'com.android.library'
android {
- compileSdkVersion 25
- buildToolsVersion "25.0.2"
+ compileSdkVersion 26
defaultConfig {
minSdkVersion 14
- targetSdkVersion 25
+ targetSdkVersion 26
versionCode 1
versionName "1.0"
}
@@ -22,10 +21,7 @@ android {
}
dependencies {
- compile fileTree(include: ['*.jar'], dir: 'libs')
- compile 'com.android.support:support-annotations:25.3.0'
-
- testCompile 'junit:junit:4.12'
+ compile 'com.android.support:support-annotations:26.1.0'
}
apply from: 'https://raw.githubusercontent.com/Commit451/gradle-android-javadocs/1.0.0/gradle-android-javadocs.gradle'
diff --git a/lifeline/src/androidTest/java/com/commit451/lifeline/ApplicationTest.java b/lifeline/src/androidTest/java/com/commit451/lifeline/ApplicationTest.java
deleted file mode 100644
index 097ea5f..0000000
--- a/lifeline/src/androidTest/java/com/commit451/lifeline/ApplicationTest.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.commit451.lifeline;
-
-import android.app.Application;
-import android.test.ApplicationTestCase;
-
-/**
- * Testing Fundamentals
- */
-public class ApplicationTest extends ApplicationTestCase {
- public ApplicationTest() {
- super(Application.class);
- }
-}
\ No newline at end of file
diff --git a/lifeline/src/main/java/com/commit451/lifeline/InternalBackgroundListener.java b/lifeline/src/main/java/com/commit451/lifeline/InternalBackgroundListener.java
new file mode 100644
index 0000000..eef598c
--- /dev/null
+++ b/lifeline/src/main/java/com/commit451/lifeline/InternalBackgroundListener.java
@@ -0,0 +1,6 @@
+package com.commit451.lifeline;
+
+interface InternalBackgroundListener {
+
+ void onBackgrounded();
+}
diff --git a/lifeline/src/main/java/com/commit451/lifeline/Lifeline.java b/lifeline/src/main/java/com/commit451/lifeline/Lifeline.java
index 7dc21d9..4ed150c 100644
--- a/lifeline/src/main/java/com/commit451/lifeline/Lifeline.java
+++ b/lifeline/src/main/java/com/commit451/lifeline/Lifeline.java
@@ -2,10 +2,14 @@
import android.app.Activity;
import android.app.Application;
+import android.content.ComponentCallbacks2;
+import android.content.res.Configuration;
import android.os.Bundle;
import android.support.annotation.Nullable;
import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.List;
/**
* Keeps a pulse on your application
@@ -13,6 +17,7 @@
public class Lifeline {
private static TrackedLifecycleCallbacks lifecycleHandler;
+ private static List onBackgroundedListeners = new ArrayList<>();
/**
* Hooks your Application up to this Lifeline
@@ -21,6 +26,14 @@ public class Lifeline {
*/
public static void init(Application application) {
lifecycleHandler = new TrackedLifecycleCallbacks();
+ application.registerComponentCallbacks(new BackgroundComponentCallbacks2(new InternalBackgroundListener() {
+ @Override
+ public void onBackgrounded() {
+ for (OnBackgroundedListener listener : onBackgroundedListeners) {
+ listener.onBackgrounded();
+ }
+ }
+ }));
application.registerActivityLifecycleCallbacks(lifecycleHandler);
}
@@ -96,12 +109,45 @@ public static Activity getCurrentStartedActivity() {
return null;
}
+ public static void register(OnBackgroundedListener listener) {
+ onBackgroundedListeners.add(listener);
+ }
+
+ public static void unregister(OnBackgroundedListener listener) {
+ onBackgroundedListeners.remove(listener);
+ }
+
private static void checkInit() {
if (lifecycleHandler == null) {
throw new IllegalStateException("You need to first call `init()` on this class before using it");
}
}
+ private static class BackgroundComponentCallbacks2 implements ComponentCallbacks2 {
+
+ private InternalBackgroundListener listener;
+
+ public BackgroundComponentCallbacks2(InternalBackgroundListener listener) {
+ this.listener = listener;
+ }
+
+ @Override
+ public void onTrimMemory(int level) {
+ if (level == ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
+ // We're in the Background
+ listener.onBackgrounded();
+ }
+ }
+
+ @Override
+ public void onLowMemory() {
+ }
+
+ @Override
+ public void onConfigurationChanged(Configuration newConfig) {
+ }
+ }
+
/**
* Inspired by
* http://stackoverflow.com/questions/3667022/checking-if-an-android-application-is-running-in-the-background/13809991#13809991
diff --git a/lifeline/src/main/java/com/commit451/lifeline/OnBackgroundedListener.java b/lifeline/src/main/java/com/commit451/lifeline/OnBackgroundedListener.java
new file mode 100644
index 0000000..1be52e0
--- /dev/null
+++ b/lifeline/src/main/java/com/commit451/lifeline/OnBackgroundedListener.java
@@ -0,0 +1,12 @@
+package com.commit451.lifeline;
+
+/**
+ * Listener for when the app is backgrounded
+ */
+public interface OnBackgroundedListener {
+
+ /**
+ * The app has been backgrounded
+ */
+ void onBackgrounded();
+}
diff --git a/lifeline/src/test/java/com/commit451/lifeline/ExampleUnitTest.java b/lifeline/src/test/java/com/commit451/lifeline/ExampleUnitTest.java
deleted file mode 100644
index c993b5c..0000000
--- a/lifeline/src/test/java/com/commit451/lifeline/ExampleUnitTest.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.commit451.lifeline;
-
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * To work on unit tests, switch the Test Artifact in the Build Variants view.
- */
-public class ExampleUnitTest {
- @Test
- public void addition_isCorrect() throws Exception {
- assertEquals(4, 2 + 2);
- }
-}
\ No newline at end of file