Skip to content

Instantly share code, notes, and snippets.

@AmandaCameron
Created May 29, 2016 20:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AmandaCameron/0d80d4500c27ba10285f026845ee5918 to your computer and use it in GitHub Desktop.
Save AmandaCameron/0d80d4500c27ba10285f026845ee5918 to your computer and use it in GitHub Desktop.
package net.darkdna.amanda.standaloneweartest.complications;
import android.graphics.drawable.Icon;
import android.os.AsyncTask;
import android.support.wearable.complications.ComplicationData;
import android.support.wearable.complications.ComplicationManager;
import android.support.wearable.complications.ComplicationProviderService;
import android.util.Log;
import com.google.android.apps.muzei.api.MuzeiContract;
import java.io.FileNotFoundException;
/**
* Simple Muzei current image forwarding from the API to an LARGE_IMAGE complication.
*
* Created by amandacameron on 5/29/16.
*/
public class CurrentMuzeiComplication extends ComplicationProviderService {
static final String TAG = "CurrentMuzeiProvider";
@Override
public void onComplicationUpdate(int complId, int type, ComplicationManager complicationManager) {
if(type == ComplicationData.TYPE_LARGE_IMAGE) {
new GetArtworkTask(complId, complicationManager).execute();
}
}
private class GetArtworkTask extends AsyncTask<Void, Void, ComplicationData> {
private ComplicationManager complicationManager;
private int complId;
public GetArtworkTask(int complId, ComplicationManager complicationManager) {
this.complicationManager = complicationManager;
this.complId = complId;
}
@Override
protected ComplicationData doInBackground(Void... params) {
try {
return new ComplicationData.Builder(ComplicationData.TYPE_LARGE_IMAGE)
.setLargeImage(Icon.createWithBitmap(
MuzeiContract.Artwork.getCurrentArtworkBitmap(CurrentMuzeiComplication.this)))
.build();
} catch(FileNotFoundException e) {
Log.e(TAG, "Couldn't load image.", e);
}
return null;
}
@Override
protected void onPostExecute(ComplicationData data) {
complicationManager.updateComplicationData(complId, data);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment