diff --git a/app/build.gradle b/app/build.gradle
index a5ca220..a3c7fd1 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -25,4 +25,5 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.apache.commons:commons-math3:3.5'
+ compile 'com.actionlauncher:action3-api:1.+'
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 576afcd..c37eb60 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -64,6 +64,13 @@
+
+
+
+
+
diff --git a/app/src/main/java/com/androidexperiments/meter/MeterWallpaper.java b/app/src/main/java/com/androidexperiments/meter/MeterWallpaper.java
index 92dec45..077c589 100644
--- a/app/src/main/java/com/androidexperiments/meter/MeterWallpaper.java
+++ b/app/src/main/java/com/androidexperiments/meter/MeterWallpaper.java
@@ -1,10 +1,13 @@
package com.androidexperiments.meter;
import android.content.Context;
+import android.graphics.Bitmap;
import android.graphics.Canvas;
+import android.graphics.Rect;
import android.os.Bundle;
import android.os.Handler;
import android.service.wallpaper.WallpaperService;
+import android.util.Log;
import android.view.SurfaceHolder;
import java.util.ArrayList;
@@ -14,6 +17,8 @@
import com.androidexperiments.meter.drawers.Drawer;
import com.androidexperiments.meter.drawers.NotificationsDrawer;
+import com.actionlauncher.api.LiveWallpaperSource;
+
/**
* The Live Wallpaper Service and rendering Engine
*/
@@ -26,6 +31,10 @@ public class MeterWallpaper extends WallpaperService {
// Variable containing the index of the drawer last shown
private int mDrawerIndex = -1;
+ // Whether we have to update actionlauncher with a new wallpaper
+ // ONLY set to true if actionlauncher was updated SUCCESSFULLY
+ private boolean mUpdateActionLauncher;
+
@Override
public Engine onCreateEngine() {
WallpaperEngine engine = new WallpaperEngine(this);
@@ -81,12 +90,28 @@ private void draw() {
if(mDrawer.shouldDraw()) {
SurfaceHolder holder = getSurfaceHolder();
Canvas c = null;
+ Bitmap bmp = null;
+ // Draw into a Bitmap which will then be sent to ActionLauncher
+ if (mUpdateActionLauncher) {
+ Rect surfaceFrame = holder.getSurfaceFrame();
+ bmp = Bitmap.createBitmap(surfaceFrame.width(), surfaceFrame.height(), Bitmap.Config.ARGB_8888);
+ c = new Canvas(bmp);
+ if (c != null) {
+ // Let the drawer render to the canvas
+ mDrawer.draw(c);
+ }
+ updateActionLauncher(bmp);
+ }
try {
// Lock the drawing canvas
c = holder.lockCanvas();
if (c != null) {
- // Let the drawer render to the canvas
- mDrawer.draw(c);
+ if (bmp != null) {
+ c.drawBitmap(bmp, 0, 0, null);
+ } else {
+ // Let the drawer render to the canvas
+ mDrawer.draw(c);
+ }
}
} finally {
if (c != null) holder.unlockCanvasAndPost(c);
@@ -99,6 +124,28 @@ private void draw() {
}
}
+ // Taken from the ActionLauncher API Documentation
+ private void updateActionLauncher(Bitmap bmp) {
+ if (bmp != null) {
+ try {
+ LiveWallpaperSource.with(mContext)
+ .setBitmapSynchronous(bmp)
+ .run();
+ mUpdateActionLauncher = false;
+ } catch (OutOfMemoryError outOfMemoryError) {
+ // Palette generation was unable to process the Bitmap passed in to
+ // setBitmapSynchronous(). Consider using a smaller image.
+ // See ActionPalette.DEFAULT_RESIZE_BITMAP_MAX_DIMENSION
+ Log.e(TAG, "Error setting ActionLauncher LiveWallpaper", outOfMemoryError);
+ } catch (IllegalArgumentException illegalArgumentEx) {
+ // Raised during palette generation. Check your Bitmap.
+ Log.e(TAG, "Error setting ActionLauncher LiveWallpaper", illegalArgumentEx);
+ } catch (IllegalStateException illegalStateException) {
+ // Raised during palette generation. Check your Bitmap.
+ Log.e(TAG, "Error setting ActionLauncher LiveWallpaper", illegalStateException);
+ }
+ }
+ }
/**
* Toggle visibility of the wallpaper
@@ -135,7 +182,9 @@ public void onVisibilityChanged(boolean visible) {
}
mDrawer.start();
- // Start the drawing loop
+
+ // Start the drawing loop and make sure ActionLauncher will get updated
+ mUpdateActionLauncher = true;
draw();
} else {
@@ -149,6 +198,7 @@ public void onVisibilityChanged(boolean visible) {
@Override
public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
+ mUpdateActionLauncher = true;
draw();
}